Fix isvalidatom() so tests pass, and add a USE deps case to the tests.
authorZac Medico <zmedico@gentoo.org>
Sun, 25 May 2008 03:13:06 +0000 (03:13 -0000)
committerZac Medico <zmedico@gentoo.org>
Sun, 25 May 2008 03:13:06 +0000 (03:13 -0000)
(trunk r10399)

svn path=/main/branches/2.1.2/; revision=10401

pym/portage_dep.py
pym/portage_versions.py
tests/portage_dep/test_isvalidatom.py

index 4fe95d9b309b0ae3169876e60b4a9432ade5b32f..bad51b6468f7bf6d6d88a2ceea0760c84c3ca7ba 100644 (file)
@@ -369,6 +369,7 @@ def remove_slot(mydep):
                mydep = mydep[:colon]
        return mydep
 
+_valid_category = re.compile("^\w[\w-]*")
 _invalid_atom_chars_regexp = re.compile("[()|?@\[\]]")
 
 def isvalidatom(atom, allow_blockers=False):
@@ -393,10 +394,13 @@ def isvalidatom(atom, allow_blockers=False):
                return 0
        if allow_blockers and atom.startswith("!"):
                atom = atom[1:]
-       try:
-               mycpv_cps = catpkgsplit(dep_getcpv(atom))
-       except InvalidData:
-               return 0
+       cpv = dep_getcpv(atom)
+       if cpv:
+               if _valid_category.match(catsplit(cpv)[0]) is None:
+                       return 0
+               mycpv_cps = catpkgsplit(cpv)
+       else:
+               mycpv_cps = None
        operator = get_operator(atom)
        if operator:
                if operator[0] in "<>" and remove_slot(atom).endswith("*"):
index ff31fbd4e828d7dc11a5413b9070ef7306a889f5..e28f174bbb4b9d1988ec8f3ffa6ec2b122b00e6c 100644 (file)
@@ -255,8 +255,6 @@ def pkgsplit(mypkg,silent=1):
                pkgcache[mypkg]=None
                return None
 
-_valid_category = re.compile("^\w[\w-]*")
-
 catcache={}
 def catpkgsplit(mydata,silent=1):
        """
@@ -271,13 +269,8 @@ def catpkgsplit(mydata,silent=1):
        1.  If each exists, it returns [cat, pkgname, version, rev]
        2.  If cat is not specificed in mydata, cat will be "null"
        3.  if rev does not exist it will be '-r0'
-       4.  If cat is invalid (specified but has incorrect syntax)
-               an InvalidData Exception will be thrown
        """
-       
-       # Categories may contain a-zA-z0-9+_- but cannot start with -
-       global _valid_category
-       import portage_dep
+
        try:
                if not catcache[mydata]:
                        return None
@@ -290,9 +283,6 @@ def catpkgsplit(mydata,silent=1):
                retval=["null"]
                p_split=pkgsplit(mydata,silent=silent)
        elif len(mysplit)==2:
-               if portage_dep._dep_check_strict and \
-                       not _valid_category.match(mysplit[0]):
-                       raise InvalidData("Invalid category in %s" %mydata )
                retval=[mysplit[0]]
                p_split=pkgsplit(mysplit[1],silent=silent)
        if not p_split:
index e0a4e21798757d2378d04c745f96694d7df21727..cf82f144f3d412fbac980fa182f79788ca994ee5 100644 (file)
@@ -22,6 +22,10 @@ class IsValidAtom(TestCase):
                          ( ">sys-apps/portage-2.1", True ),
                          ( "<sys-apps/portage-2.1", True ),
                          ( "~sys-apps/portage-2.1", True ),
+                         ( "sys-apps/portage:foo", True ),
+                         ( "sys-apps/portage-2.1:foo", False ),
+                         ( "sys-apps/portage-2.1:", False ),
+                         ( "=sys-apps/portage-2.2*:foo[bar][-baz][doc?][-build?]", False ),
                          ( ">~cate-gory/foo-1.0", False ),
                          ( ">~category/foo-1.0", False ),
                          ( "<~category/foo-1.0", False ),