From 211b56614083fbb4f78b74f28a3962f97bf684d5 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Tue, 1 Jul 2008 12:55:49 +0000 Subject: [PATCH] Py3k compatibility patch #6 by Ali Polatel . Replace dict.has_key() calls with "in" and "not in" operators. svn path=/main/trunk/; revision=10875 --- pym/portage/__init__.py | 4 ++++ pym/portage/cache/mappings.py | 11 ++++++++++- pym/portage/cache/template.py | 4 ++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index d5b82ec13..06193e717 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -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): diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index 2ccc96b05..d0ca487f0 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -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 diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index d5a07528c..891a5821f 100644 --- a/pym/portage/cache/template.py +++ b/pym/portage/cache/template.py @@ -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): -- 2.26.2