Implement a substitute for UserDict.UserDict so that code converted via
authorZac Medico <zmedico@gentoo.org>
Wed, 11 Mar 2009 05:43:56 +0000 (05:43 -0000)
committerZac Medico <zmedico@gentoo.org>
Wed, 11 Mar 2009 05:43:56 +0000 (05:43 -0000)
2to3 will run:

     http://bugs.python.org/issue2876 (trunk r12629)

svn path=/main/branches/2.1.6/; revision=12902

pym/portage/cache/mappings.py
pym/portage/env/config.py

index 74ed5fa5eeae1cc90d1c369aff45c001bbd1cc98..a368050bacae73aad30fec0ea5cd9ba9dfa5ac78 100644 (file)
@@ -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
index c990d9f0effe3b80661ac6ecc7bd909415e48495..9a446df0e41cc12b79b0652b0d15df6df7d67eed 100644 (file)
@@ -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.