Fix incorrect parse check as value lists in KeyListFileLoader might be empty, add...
authorMarius Mauch <genone@gentoo.org>
Fri, 7 Sep 2007 12:30:00 +0000 (12:30 -0000)
committerMarius Mauch <genone@gentoo.org>
Fri, 7 Sep 2007 12:30:00 +0000 (12:30 -0000)
svn path=/main/trunk/; revision=7757

pym/portage/env/loaders.py

index 7b1da91b7664e70d60b22d6c864b0c897d81c1c6..ba250ecd47ac1a97b2f974bbbdcb24aaae09cd00 100644 (file)
@@ -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: