Make isspecific() use the Atom class and fall back to legacy code if the
authorZac Medico <zmedico@gentoo.org>
Mon, 14 Sep 2009 06:49:01 +0000 (06:49 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 14 Sep 2009 06:49:01 +0000 (06:49 -0000)
atom is invalid. Also, optimize called isjustname() legacy code to only
check the last 2 components.

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

pym/portage/dep.py

index 8dbcdd65718f03edbca569adaf395d54523c6e6f..38a84dc72605260ae9a8034fc2a5b90f596de179 100644 (file)
@@ -892,7 +892,6 @@ _op = r'([=~]|[><]=?)'
 _cp = '(' + _cat + '/' + _pkg + '(-' + _version + ')?)'
 _cpv = '(' + _cp + '-' + _version + ')'
 
-_cpv_re = re.compile('^' + _cpv + '$', re.VERBOSE)
 _atom_re = re.compile('^(?:' +
        '(?P<op>' + _op + _cpv + ')|' +
        '(?P<star>=' + _cpv + r'\*)|' +
@@ -945,23 +944,20 @@ def isjustname(mypkg):
        except InvalidAtom:
                pass
 
-       myparts = mypkg.split('-')
-       for x in myparts:
+       for x in mypkg.split('-')[-2:]:
                if ververify(x):
                        return False
        return True
 
-iscache = {}
-
 def isspecific(mypkg):
        """
-       Checks to see if a package is in category/package-version or package-version format,
-       possibly returning a cached result.
+       Checks to see if a package is in =category/package-version or
+       package-version format.
 
        Example usage:
                >>> isspecific('media-libs/test')
                False
-               >>> isspecific('media-libs/test-3.0')
+               >>> isspecific('=media-libs/test-3.0')
                True
 
        @param mypkg: The package depstring to check against
@@ -972,12 +968,12 @@ def isspecific(mypkg):
                2) True if it is
        """
        try:
-               return iscache[mypkg]
-       except KeyError:
+               return mypkg != Atom(mypkg).cp
+       except InvalidAtom:
                pass
-       retval = _cpv_re.match(mypkg) is not None
-       iscache[mypkg] = retval
-       return retval
+
+       # Fall back to legacy code for backward compatibility.
+       return not isjustname(mypkg)
 
 def dep_getkey(mydep):
        """