[Secure-testing-commits] r14653 - in lib/python: sectracker sectracker_test

Florian Weimer fw at alioth.debian.org
Sun May 9 13:59:30 UTC 2010


Author: fw
Date: 2010-05-09 13:59:28 +0000 (Sun, 09 May 2010)
New Revision: 14653

Modified:
   lib/python/sectracker/parsers.py
   lib/python/sectracker_test/test_parsers.py
Log:
sectracker.parsers._annotationdispatcher: return annotation

No longer pass in the list to add to.


Modified: lib/python/sectracker/parsers.py
===================================================================
--- lib/python/sectracker/parsers.py	2010-05-09 11:39:28 UTC (rev 14652)
+++ lib/python/sectracker/parsers.py	2010-05-09 13:59:28 UTC (rev 14653)
@@ -23,7 +23,7 @@
 import sectracker.xpickle as _xpickle
 import sectracker.diagnostics
 
-FORMAT = "3"
+FORMAT = "4"
 
 def _sortedtuple(seq):
     l = list(seq)
@@ -129,56 +129,55 @@
 
     @_regexpcase.rule(r'(?:\[([a-z]+)\]\s)?-\s([A-Za-z0-9:.+-]+)\s*'
                       + r'(?:\s([A-Za-z0-9:.+~-]+)\s*)?(?:\s\((.*)\))?')
-    def package_version(groups, diag, anns):
+    def package_version(groups, diag):
         release, package, version, inner = groups
         inner = parseinner(diag, inner)
         if version is None:
             kind = "unfixed"
         else:
             kind = "fixed"
-        anns.append(PackageAnnotation(
-                *((diag.line(), "package", release, package, kind,
-                   version, None) + inner)))
+        return PackageAnnotation(
+            *((diag.line(), "package", release, package, kind,
+               version, None) + inner))
 
     pseudo_freetext = "no-dsa not-affected end-of-life".split()
     pseudo_struct = set("unfixed removed itp undetermined".split())
     @_regexpcase.rule(r'(?:\[([a-z]+)\]\s)?-\s([A-Za-z0-9:.+-]+)'
                       + r'\s+<([a-z-]+)>\s*(?:\s\((.*)\))?')
-    def package_pseudo(groups, diag, anns):
+    def package_pseudo(groups, diag):
         release, package, version, inner = groups
         if version in pseudo_freetext:
-            anns.append(PackageAnnotation(
-                    diag.line(), "package", release, package, version,
-                    None, inner, None, (), False))
+            return PackageAnnotation(
+                diag.line(), "package", release, package, version,
+                None, inner, None, (), False)
         elif version in pseudo_struct:
             inner = parseinner(diag, inner)
             if version == "itp" and not inner[1]:
                 diag.error("<itp> needs Debian bug reference")
-            anns.append(PackageAnnotation(
-                    *((diag.line(), "package", release, package, version,
-                       None, None) + inner)))
+            return PackageAnnotation(
+                *((diag.line(), "package", release, package, version,
+                   None, None) + inner))
         else:
             diag.error("invalid pseudo-version: " + repr(version))
+            return None
 
     @_regexpcase.rule(r'\{(.*)\}')
-    def xref(groups, diag, anns):
+    def xref(groups, diag):
         x = _sortedtuple(groups[0].strip().split())
         if x:
-            anns.append(XrefAnnotation(diag.line(), "xref", x))
+            return XrefAnnotation(diag.line(), "xref", x)
         else:
             diag.error("empty cross-reference")
+            return None
         
     return _regexpcase.RegexpCase(
         ((r'(RESERVED|REJECTED)',
-          lambda groups, diag, anns:
-              anns.append(FlagAnnotation(diag.line(), groups[0]))),
+          lambda groups, diag: FlagAnnotation(diag.line(), groups[0])),
          (r'(NOT-FOR-US|NOTE|TODO):\s+(\S.*)',
-          lambda groups, diag, anns:
-              anns.append(StringAnnotation(diag.line(), *groups))),
+          lambda groups, diag: StringAnnotation(diag.line(), *groups)),
          package_version, package_pseudo, xref),
         prefix=r"\s+", suffix=r"\s*",
-        default=lambda text, diag, anns:
-            diag.error("invalid annotation"))
+        default=lambda text, diag: diag.error("invalid annotation"))
 _annotationdispatcher = _annotationdispatcher()
 
 List = _namedtuple("List", "list messages")
@@ -201,7 +200,9 @@
             if header is None:
                 diag.error("header expected")
                 continue
-            _annotationdispatcher(line, diag, anns)
+            ann = _annotationdispatcher(line, diag)
+            if ann is not None:
+                anns.append(ann)
         else:
             if header is not None:
                 bugs.append(finish(header, headerlineno, anns, diag))

Modified: lib/python/sectracker_test/test_parsers.py
===================================================================
--- lib/python/sectracker_test/test_parsers.py	2010-05-09 11:39:28 UTC (rev 14652)
+++ lib/python/sectracker_test/test_parsers.py	2010-05-09 13:59:28 UTC (rev 14653)
@@ -114,14 +114,9 @@
          (Message("CVE", 17, "error",
                   "invalid pseudo-version: 'garbled'"),)),
         ]:
-    anns = []
     diag = sectracker.diagnostics.Diagnostics()
     diag.setlocation("CVE", 17)
-    p._annotationdispatcher(line, diag, anns)
+    r = p._annotationdispatcher(line, diag)
     msgs = diag.messages()
     assert tuple(msgs) == xmsgs, repr(msgs)
-    if anns:
-        r = anns[0]
-    else:
-        r = None
-    assert r == res, repr(anns)
+    assert r == res, repr(r)




More information about the Secure-testing-commits mailing list