From ad68fd1894e1905597ec7bc9f40f629b9b2f92a7 Mon Sep 17 00:00:00 2001 From: Marius Mauch Date: Fri, 7 Sep 2007 12:30:00 +0000 Subject: [PATCH] Fix incorrect parse check as value lists in KeyListFileLoader might be empty, add support for value validators in relevant Loaders svn path=/main/trunk/; revision=7757 --- pym/portage/env/loaders.py | 37 ++++++++++++++++++++++++++++++++----- 1 file 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: -- 2.26.2