diff options
author | Zac Medico <zmedico@gentoo.org> | 2009-02-19 03:27:40 +0000 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2009-02-19 03:27:40 +0000 |
commit | 746f69f17187178d79c29c0670be8095ef524ae3 (patch) | |
tree | eb7eb0b0038bd2c6499ec36cb2d79232538c42c1 /pym/portage/cache/mappings.py | |
parent | f522aabc3ddc4a55513c75a39d0b11378ba8f41b (diff) | |
download | portage-746f69f17187178d79c29c0670be8095ef524ae3.tar.gz portage-746f69f17187178d79c29c0670be8095ef524ae3.tar.bz2 portage-746f69f17187178d79c29c0670be8095ef524ae3.zip |
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
Diffstat (limited to 'pym/portage/cache/mappings.py')
-rw-r--r-- | pym/portage/cache/mappings.py | 40 |
1 files changed, 38 insertions, 2 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 |