From 4d846f968f4a1e2671b64a18a4b6b1371b8f5e41 Mon Sep 17 00:00:00 2001 From: chrisr3d Date: Fri, 26 Jan 2018 17:11:01 +0100 Subject: [PATCH] Updated delimiter parsing & data reading functions --- misp_modules/modules/import_mod/csvimport.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/misp_modules/modules/import_mod/csvimport.py b/misp_modules/modules/import_mod/csvimport.py index fc5b4e7..e5ff3b0 100644 --- a/misp_modules/modules/import_mod/csvimport.py +++ b/misp_modules/modules/import_mod/csvimport.py @@ -24,13 +24,17 @@ def handler(q=False): misperrors['error'] = "Configuration error" return misperrors config = request['config'].get('header') - header = [] + #header = [] data = [] with open(filename, 'r') as f: for line in f: # split comments from data - if line.startswith('#'): - header.append(line) + if '#' in line: + l = line.split('#')[0] + if l: + data.append(l) + #else: + #header.append(line) else: data.append(line) # find which delimiter is used @@ -43,10 +47,9 @@ def handler(q=False): def findDelimiter(header, data): n = len(header) if n > 1: - for d in (';', ',', '|'): + for d in (';', '|', '/', ','): if data[0].count(d) == (n-1): return d, n - break else: return None, 1 @@ -100,6 +103,7 @@ def findMispTypes(header): elif h in duplicatedFields['attrField']: # fields that should be considered as attribute fields head.append(duplicatedFields['attrField'].get(h)) + # otherwise, it is an attribute field else: head.append(h) # return list of indexes of the misp types, list of the misp types, remaining fields that will be attribute fields