From: Zac Medico Date: Wed, 11 Mar 2009 03:40:57 +0000 (-0000) Subject: For python-3.0 compatibility, make dict-like classes modify their keys(), X-Git-Tag: v2.1.6.8~212 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ac7e06f390c7bb66e6c11c8af27215dc9e7a169e;p=portage.git For python-3.0 compatibility, make dict-like classes modify their keys(), items(), and values() methods appropriatly for the current python version. (trunk r12584) svn path=/main/branches/2.1.6/; revision=12865 --- diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index a3884cc56..20fb6ba2f 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2973,6 +2973,10 @@ class config(object): pass return self._selinux_enabled + if sys.hexversion >= 0x3000000: + keys = __iter__ + items = iteritems + def _shell_quote(s): """ Quote a string in double-quotes and use backslashes to diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py index 47b8ac1bd..9007a1a56 100644 --- a/pym/portage/cache/anydbm.py +++ b/pym/portage/cache/anydbm.py @@ -9,6 +9,7 @@ try: except ImportError: import pickle import os +import sys from portage.cache import fs_template from portage.cache import cache_errors @@ -70,3 +71,6 @@ class database(fs_template.FsBased): if "__db" in self.__dict__ and self.__db != None: self.__db.sync() self.__db.close() + + if sys.hexversion >= 0x3000000: + items = iteritems diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index 112301476..010eb7f8e 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -3,6 +3,7 @@ # License: GPL2 # $Id$ +import sys import UserDict import warnings import weakref @@ -65,6 +66,10 @@ class ProtectedDict(UserDict.DictMixin): DeprecationWarning) return key in self + if sys.hexversion >= 0x3000000: + keys = __iter__ + items = iteritems + class LazyLoad(UserDict.DictMixin): """ Lazy loading of values for a dict @@ -111,6 +116,10 @@ class LazyLoad(UserDict.DictMixin): self.pull = None return key in self.d + if sys.hexversion >= 0x3000000: + keys = __iter__ + items = iteritems + _slot_dict_classes = weakref.WeakValueDictionary() def slot_dict_class(keys, prefix="_val_"): @@ -265,6 +274,11 @@ def slot_dict_class(keys, prefix="_val_"): def __str__(self): return str(dict(self.iteritems())) + if sys.hexversion >= 0x3000000: + items = iteritems + keys = __iter__ + values = itervalues + v = SlotDict _slot_dict_classes[v.allowed_keys] = v return v diff --git a/pym/portage/cache/sql_template.py b/pym/portage/cache/sql_template.py index fe873c3ea..e5903cd67 100644 --- a/pym/portage/cache/sql_template.py +++ b/pym/portage/cache/sql_template.py @@ -3,6 +3,7 @@ # License: GPL2 # $Id$ +import sys from portage.cache import template, cache_errors from portage.cache.template import reconstruct_eclasses @@ -277,3 +278,5 @@ class SQLDatabase(template.database): return [ row[0] for row in self.con.fetchall() ] + if sys.hexversion >= 0x3000000: + items = iteritems diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py index 238f9dc40..35b9efeff 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 sys import warnings class database(object): @@ -177,6 +178,9 @@ class database(object): if cont: yield cpv + if sys.hexversion >= 0x3000000: + keys = __iter__ + items = iteritems def serialize_eclasses(eclass_dict): """takes a dict, returns a string representing said dict"""