Fixup csl dataset and initial (untested) file dataset

This commit is contained in:
Scott Kitterman
2018-02-25 15:57:41 -05:00
parent f381986f7a
commit ced16fda72
2 changed files with 31 additions and 5 deletions
+2
View File
@@ -1,4 +1,6 @@
0.9.3 UNRELEASED
- Fixup csl dataset processing for single item lists
- file: dataset support
0.9.2 2018-02-19
- Improved package requirements definition
+29 -5
View File
@@ -87,16 +87,40 @@ def _find_boolean(item):
def _dataset_to_list(dataset):
"""Convert a dataset (as defined in dkimpymilter.8) and return a python
list of values."""
if not isinstance(dataset, basestring):
# If it was a csl, it's already a list, we only need to remove the name
# from the first value
if not isinstance(dataset, str):
# If it was a csl with more than one value, it's already a list, we
# only need to remove the name from the first value.
if dataset[0][:4] == 'csl:':
dataset[0] = dataset[0][4:]
for item in dataset:
dataset[dataset.index(item)] = item.strip().strip(',')
return dataset
else:
raise dkim.ParameterError('Unimplmented dataset type')
elif isinstance(dataset, str):
if dataset[0] == '/' or dataset[:5] == 'file:':
# This is a flat file dataset
ds = []
if dataset[0] == '/':
dsname = dataset
if dataset[:5] == 'file:':
dsname = dataset[5:]
dsf = open(dsname, 'r')
dslines = dsf.readlines
dsf.close()
for line in dslines:
if line[0] != '#':
if len(line.split(':')) == 1:
ds.append(line.strip())
else:
for element in line.split(':'):
ds.append(element.strip().strip(':'))
return ds
# If it's a str and csl, it has one value and we return a list
if dataset[:4] == 'csl:':
return [dataset[4:].strip().strip(',')]
else:
return [dataset.strip().strip(',')]
raise dkim.ParameterError('Unimplmented dataset type: {0}'.format(type(dataset)))
###############################################################
commentRx = re.compile(r'^(.*)#.*$')