{'key':['foo1','foo2','foo3']}
"""
- def __init__(self, filename, validator):
+ def __init__(self, filename, validator=None, valuevalidator=None):
FileLoader.__init__(self, filename, validator)
+ f = valuevalidator
+ if f is None:
+ # if they pass in no validator, just make a fake one
+ # that always returns true
+ def validate(key):
+ return True
+ f = validate
+ self._valueValidate = f
def lineParser(self, line, line_num, data, errors):
line = line.strip()
if not len(line): # skip empty lines
return
split = line.split()
- if len(split) < 2:
+ if len(split) < 1:
errors.setdefault(self.fname, []).append(
"Malformed data at line: %s, data: %s"
% (line_num + 1, line))
value = split[1:]
if not self._validate(key):
errors.setdefault(self.fname, []).append(
- "Validation failed at line: %s, data %s"
+ "Key validation failed at line: %s, data %s"
% (line_num + 1, key))
return
+ if not self._valueValidate(value):
+ errors.setdefault(self.fname, []).append(
+ "Value validation failed at line: %s, data %s"
+ % (line_num + 1, value))
+ return
if key in data:
data[key].append(value)
else:
'foo':'bar'}
"""
- def __init__(self, filename, validator):
+ def __init__(self, filename, validator, valuevalidator=None):
FileLoader.__init__(self, filename, validator)
+ f = valuevalidator
+ if f is None:
+ # if they pass in no validator, just make a fake one
+ # that always returns true
+ def validate(key):
+ return True
+ f = validate
+ self._valueValidate = f
+
def lineParser(self, line, line_num, data, errors):
line = line.strip()
return
if not self._validate(key):
errors.setdefault(self.fname, []).append(
- "Validation failed at line: %s, data %s"
+ "Key validation failed at line: %s, data %s"
% (line_num + 1, key))
return
+ if not self._valueValidate(value):
+ errors.setdefault(self.fname, []).append(
+ "Value validation failed at line: %s, data %s"
+ % (line_num + 1, value))
+ return
if key in data:
data[key].append(value)
else: