Updated delimiter parsing & data reading functions

pull/156/head
chrisr3d 2018-01-26 17:11:01 +01:00
parent b9d72bb043
commit 4d846f968f
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 9 additions and 5 deletions

View File

@ -24,13 +24,17 @@ def handler(q=False):
misperrors['error'] = "Configuration error" misperrors['error'] = "Configuration error"
return misperrors return misperrors
config = request['config'].get('header') config = request['config'].get('header')
header = [] #header = []
data = [] data = []
with open(filename, 'r') as f: with open(filename, 'r') as f:
for line in f: for line in f:
# split comments from data # split comments from data
if line.startswith('#'): if '#' in line:
header.append(line) l = line.split('#')[0]
if l:
data.append(l)
#else:
#header.append(line)
else: else:
data.append(line) data.append(line)
# find which delimiter is used # find which delimiter is used
@ -43,10 +47,9 @@ def handler(q=False):
def findDelimiter(header, data): def findDelimiter(header, data):
n = len(header) n = len(header)
if n > 1: if n > 1:
for d in (';', ',', '|'): for d in (';', '|', '/', ','):
if data[0].count(d) == (n-1): if data[0].count(d) == (n-1):
return d, n return d, n
break
else: else:
return None, 1 return None, 1
@ -100,6 +103,7 @@ def findMispTypes(header):
elif h in duplicatedFields['attrField']: elif h in duplicatedFields['attrField']:
# fields that should be considered as attribute fields # fields that should be considered as attribute fields
head.append(duplicatedFields['attrField'].get(h)) head.append(duplicatedFields['attrField'].get(h))
# otherwise, it is an attribute field
else: else:
head.append(h) head.append(h)
# return list of indexes of the misp types, list of the misp types, remaining fields that will be attribute fields # return list of indexes of the misp types, list of the misp types, remaining fields that will be attribute fields