From 4f0265acc0a894c615eacce760ddfa09a970b048 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Wed, 4 Feb 2009 23:30:42 +0000 Subject: [PATCH] For python-3.0 compatibility, make dict-like classes modify their keys(), items(), and values() methods appropriatly for the current python version. svn path=/main/trunk/; revision=12584 --- pym/portage/__init__.py | 4 ++++ pym/portage/cache/anydbm.py | 4 ++++ pym/portage/cache/mappings.py | 14 ++++++++++++++ pym/portage/cache/sql_template.py | 3 +++ pym/portage/cache/template.py | 4 ++++ 5 files changed, 29 insertions(+) diff --git a/pym/portage/__init__.py b/pym/portage/__init__.py index cf0f35b13..85c970440 100644 --- a/pym/portage/__init__.py +++ b/pym/portage/__init__.py @@ -2983,6 +2983,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""" -- 2.26.2