diff options
-rw-r--r-- | pym/portage/env/loaders.py | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/pym/portage/env/loaders.py b/pym/portage/env/loaders.py index 7b1da91b7..ba250ecd4 100644 --- a/pym/portage/env/loaders.py +++ b/pym/portage/env/loaders.py @@ -196,9 +196,17 @@ class KeyListFileLoader(FileLoader): {'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() @@ -207,7 +215,7 @@ class KeyListFileLoader(FileLoader): 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)) @@ -216,9 +224,14 @@ class KeyListFileLoader(FileLoader): 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: @@ -236,9 +249,18 @@ class KeyValuePairFileLoader(FileLoader): '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() @@ -261,9 +283,14 @@ class KeyValuePairFileLoader(FileLoader): 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: |