mirror of https://github.com/MISP/misp-modules
Updated delimiter finder method
parent
529d22cca8
commit
b2ec186ccb
|
@ -30,13 +30,11 @@ def handler(q=False):
|
||||||
for line in f:
|
for line in f:
|
||||||
# split comments from data
|
# split comments from data
|
||||||
if '#' in line:
|
if '#' in line:
|
||||||
l = line.split('#')[0]
|
l = line.split('#')[0].strip()
|
||||||
if l:
|
|
||||||
data.append(l)
|
|
||||||
#else:
|
|
||||||
#header.append(line)
|
|
||||||
else:
|
else:
|
||||||
data.append(line)
|
l = line.strip()
|
||||||
|
if l:
|
||||||
|
data.append(l)
|
||||||
# find which delimiter is used
|
# find which delimiter is used
|
||||||
delimiter, length = findDelimiter(config, data)
|
delimiter, length = findDelimiter(config, data)
|
||||||
# build the attributes
|
# build the attributes
|
||||||
|
@ -47,9 +45,16 @@ 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 (';', '|', '/', ',', ' '):
|
tmpData = []
|
||||||
if data[0].count(d) == (n-1):
|
for da in data:
|
||||||
return d, n
|
tmp = []
|
||||||
|
for d in (';', '|', '/', ',', '\t', ' ',):
|
||||||
|
if da.count(d) == (n-1):
|
||||||
|
tmp.append(d)
|
||||||
|
if len(tmp) == 1 and tmp == tmpData:
|
||||||
|
return tmpData[0], n
|
||||||
|
else:
|
||||||
|
tmpData = tmp
|
||||||
else:
|
else:
|
||||||
return None, 1
|
return None, 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue