Py3k compatibility patch #6 by Ali Polatel <hawking@g.o>.
authorZac Medico <zmedico@gentoo.org>
Tue, 1 Jul 2008 12:55:49 +0000 (12:55 -0000)
committerZac Medico <zmedico@gentoo.org>
Tue, 1 Jul 2008 12:55:49 +0000 (12:55 -0000)
Replace dict.has_key() calls with "in" and "not in" operators.

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

pym/portage/__init__.py
pym/portage/cache/mappings.py
pym/portage/cache/template.py

index d5b82ec136cdbb559be26ea035c3652f71186af9..06193e7177d501dc3c91d223321ec08082f88771 100644 (file)
@@ -30,6 +30,7 @@ try:
        import UserDict
        from itertools import chain, izip
        import platform
+       import warnings
 except ImportError, e:
        sys.stderr.write("\n\n")
        sys.stderr.write("!!! Failed to complete python imports. These are internal modules for\n")
@@ -2759,6 +2760,9 @@ class config(object):
                return v
 
        def has_key(self,mykey):
+               warnings.warn("portage.config.has_key() is deprecated, "
+                       "use the in operator instead",
+                       DeprecationWarning)
                return mykey in self
 
        def __contains__(self, mykey):
index 2ccc96b05c87844bc4ea69bf4c1856f84e20ccc8..d0ca487f07dca8376512b8178c984bd6bff728c4 100644 (file)
@@ -4,6 +4,7 @@
 # $Id$
 
 import UserDict
+import warnings
 import weakref
 
 class ProtectedDict(UserDict.DictMixin):
@@ -55,9 +56,14 @@ class ProtectedDict(UserDict.DictMixin):
                return list(self.__iter__())
 
 
-       def has_key(self, key):
+       def __contains__(self, key):
                return key in self.new or (key not in self.blacklist and key in self.orig)
 
+       def has_key(self, key):
+               warnings.warn("portage.cache.mapping.ProtectedDict.has_key() is"
+                       " deprecated, use the in operator instead",
+                       DeprecationWarning)
+               return key in self
 
 class LazyLoad(UserDict.DictMixin):
        """
@@ -91,6 +97,9 @@ class LazyLoad(UserDict.DictMixin):
 
 
        def has_key(self, key):
+               warnings.warn("portage.cache.mappings.LazyLoad.has_key() is "
+                       "deprecated, use the in operator instead",
+                       DeprecationWarning)
                return key in self
 
 
index d5a07528c6766ce05d03c685951687e5ad81d43e..891a5821f715df8e7906b2a746d628982f876c1e 100644 (file)
@@ -6,6 +6,7 @@
 from portage.cache import cache_errors
 from portage.cache.cache_errors import InvalidRestriction
 from portage.cache.mappings import ProtectedDict
+import warnings
 
 class database(object):
        # this is for metadata/cache transfer.
@@ -121,6 +122,9 @@ class database(object):
                if self.has_key is database.has_key:
                        # prevent a possible recursive loop
                        raise NotImplementedError
+               warnings.warn("portage.cache.template.database.has_key() is "
+                       "deprecated, override __contains__ instead",
+                       DeprecationWarning)
                return self.has_key(cpv)
 
        def __iter__(self):