Make get_operator() use Atom, and remove unnecessary reflection code from
authorZac Medico <zmedico@gentoo.org>
Mon, 14 Sep 2009 07:02:18 +0000 (07:02 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 14 Sep 2009 07:02:18 +0000 (07:02 -0000)
dep_getkey(). Thanks to Marat Radchenko <marat@slonopotamus.org> for
suggestions.

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

pym/portage/dep.py

index 38a84dc72605260ae9a8034fc2a5b90f596de179..929e31dbe65f3d00c6891541e8bdba99379b2514 100644 (file)
@@ -710,9 +710,13 @@ def get_operator(mydep):
        @return: The operator. One of:
                '~', '=', '>', '<', '=*', '>=', or '<='
        """
-       operator = getattr(mydep, "operator", False)
-       if operator is not False:
-               return operator
+       try:
+               return Atom(mydep).operator
+       except InvalidAtom:
+               pass
+
+       # Fall back to legacy code for backward compatibility.
+       operator = None
        if mydep:
                mydep = remove_slot(mydep)
        if not mydep:
@@ -988,9 +992,6 @@ def dep_getkey(mydep):
        @rtype: String
        @return: The package category/package-version
        """
-       cp = getattr(mydep, "cp", None)
-       if cp is not None:
-               return cp
 
        try:
                return Atom(mydep).cp