Fix apparent breakage from r11593 (slot dep support):
authorZac Medico <zmedico@gentoo.org>
Wed, 8 Oct 2008 22:35:31 +0000 (22:35 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 8 Oct 2008 22:35:31 +0000 (22:35 -0000)
* Handle KeyError from element.getAttribute() in makeAtom() and makeVersion().
* Avoid 'sre_constants.error: unmatched group' exceptions in revisionMatch()
  when the atom does not have a slot.

svn path=/main/trunk/; revision=11659

pym/portage/glsa.py

index 33d3cf027cf6a796e50eb599d580bc14c19d3708..a16b98c2c040f0fe8890c6c69557bbd60f1987af 100644 (file)
@@ -226,8 +226,13 @@ def makeAtom(pkgname, versionNode):
        rValue = opMapping[versionNode.getAttribute("range")] \
                                + pkgname \
                                + "-" + getText(versionNode, format="strip")
-       if "slot" in versionNode.attributes and versionNode.getAttribute("slot") != "*":
-               rValue += ":"+versionNode.getAttribute("slot")
+       try:
+               slot = versionNode.getAttribute("slot").strip()
+       except KeyError:
+               pass
+       else:
+               if slot and slot != "*":
+                       rValue += ":" + slot
        return str(rValue)
 
 def makeVersion(versionNode):
@@ -243,8 +248,13 @@ def makeVersion(versionNode):
        """
        rValue = opMapping[versionNode.getAttribute("range")] \
                        + getText(versionNode, format="strip")
-       if "slot" in versionNode.attributes and versionNode.getAttribute("slot") != "*":
-               rValue += ":"+versionNode.getAttribute("slot")
+       try:
+               slot = versionNode.getAttribute("slot").strip()
+       except KeyError:
+               pass
+       else:
+               if slot and slot != "*":
+                       rValue += ":" + slot
        return rValue
 
 def match(atom, dbapi, match_type="default"):
@@ -288,9 +298,15 @@ def revisionMatch(revisionAtom, dbapi, match_type="default"):
        @return:        a list with the matching versions
        """
        if match_type == "default" or not hasattr(dbapi, "xmatch"):
-               mylist = dbapi.match(re.sub(r'-r[0-9]+(:[^ ]+)?$', r'\1', revisionAtom[2:]))
+               if ":" in revisionAtom:
+                       mylist = dbapi.match(re.sub(r'-r[0-9]+(:[^ ]+)?$', r'\1', revisionAtom[2:]))
+               else:
+                       mylist = dbapi.match(re.sub("-r[0-9]+$", "", revisionAtom[2:]))
        else:
-               mylist = dbapi.xmatch(match_type, re.sub(r'-r[0-9]+(:[^ ]+)?$', r'\1', revisionAtom[2:]))
+               if ":" in revisionAtom:
+                       mylist = dbapi.xmatch(match_type, re.sub(r'-r[0-9]+(:[^ ]+)?$', r'\1', revisionAtom[2:]))
+               else:
+                       mylist = dbapi.xmatch(match_type, re.sub("-r[0-9]+$", "", revisionAtom[2:]))
        rValue = []
        for v in mylist:
                r1 = pkgsplit(v)[-1][1:]