From 746f69f17187178d79c29c0670be8095ef524ae3 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Thu, 19 Feb 2009 03:27:40 +0000 Subject: [PATCH] Implement a substitute for UserDict.UserDict so that code converted via 2to3 will run: http://bugs.python.org/issue2876 svn path=/main/trunk/; revision=12629 --- pym/portage/cache/mappings.py | 40 +++++++++++++++++++++++++++++++++-- pym/portage/env/config.py | 9 +++++--- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py index 74ed5fa5e..a368050ba 100644 --- a/pym/portage/cache/mappings.py +++ b/pym/portage/cache/mappings.py @@ -1,8 +1,11 @@ -# Copyright: 2005 Gentoo Foundation +# Copyright: 2005-2009 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 # Author(s): Brian Harring (ferringb@gentoo.org) -# License: GPL2 # $Id$ +__all__ = ["Mapping", "MutableMapping", "UserDict", "ProtectedDict", + "LazyLoad", "slot_dict_class"] + import sys import warnings import weakref @@ -123,6 +126,39 @@ class MutableMapping(Mapping): if kwargs: self.update(kwargs) +class UserDict(MutableMapping): + """ + Use this class as a substitute for UserDict.UserDict so that + code converted via 2to3 will run: + + http://bugs.python.org/issue2876 + """ + + def __init__(self, dict=None, **kwargs): + self.data = {} + if dict is not None: + self.update(dict) + if kwargs: + self.update(kwargs) + + def __repr__(self): + return repr(self.data) + + def __len__(self): + return len(self.data) + + def __getitem__(self, key): + return self.data[key] + + def __setitem__(self, key, item): + self.data[key] = item + + def __delitem__(self, key): + del self.data[key] + + def clear(self): + self.data.clear() + class ProtectedDict(MutableMapping): """ given an initial dict, this wraps that dict storing changes in a secondary dict, protecting diff --git a/pym/portage/env/config.py b/pym/portage/env/config.py index c990d9f0e..9a446df0e 100644 --- a/pym/portage/env/config.py +++ b/pym/portage/env/config.py @@ -1,12 +1,15 @@ # config.py -- Portage Config -# Copyright 2007 Gentoo Foundation +# Copyright 2007-2009 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Id$ -from UserDict import UserDict +__all__ = ["ConfigLoaderKlass", "GenericFile", "PackageKeywordsFile", + "PackageUseFile", "PackageMaskFile", "PortageModulesFile"] + +from portage.cache.mappings import UserDict from portage.env.loaders import KeyListFileLoader, KeyValuePairFileLoader, ItemFileLoader -class ConfigLoaderKlass(UserDict, object): +class ConfigLoaderKlass(UserDict): """ A base class stub for things to inherit from. Users may want a non-file backend. -- 2.26.2