[Python-3000-checkins] r60571 - in python/branches/py3k/Lib: _abcoll.py bsddb/dbshelve.py dumbdbm.py shelve.py

raymond.hettinger python-3000-checkins at python.org
Mon Feb 4 21:44:32 CET 2008


Author: raymond.hettinger
Date: Mon Feb  4 21:44:31 2008
New Revision: 60571

Modified:
   python/branches/py3k/Lib/_abcoll.py
   python/branches/py3k/Lib/bsddb/dbshelve.py
   python/branches/py3k/Lib/dumbdbm.py
   python/branches/py3k/Lib/shelve.py
Log:
Start replacing UserDict.DictMixin with collections.MutableMapping (the bsddb modules are next).

Modified: python/branches/py3k/Lib/_abcoll.py
==============================================================================
--- python/branches/py3k/Lib/_abcoll.py	(original)
+++ python/branches/py3k/Lib/_abcoll.py	Mon Feb  4 21:44:31 2008
@@ -378,6 +378,11 @@
     def values(self):
         return ValuesView(self)
 
+    def __eq__(self, other):
+        return set(self) == set(other)
+
+    def __ne__(self, other):
+        return set(self) == set(other)
 
 class MappingView(metaclass=ABCMeta):
 
@@ -485,6 +490,13 @@
         for key, value in kwds.items():
             self[key] = value
 
+    def setdefault(self, key, default=None):
+        try:
+            return self[key]
+        except KeyError:
+            self[key] = default
+        return default
+
 MutableMapping.register(dict)
 
 

Modified: python/branches/py3k/Lib/bsddb/dbshelve.py
==============================================================================
--- python/branches/py3k/Lib/bsddb/dbshelve.py	(original)
+++ python/branches/py3k/Lib/bsddb/dbshelve.py	Mon Feb  4 21:44:31 2008
@@ -38,12 +38,12 @@
     HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
     def _dumps(object, protocol):
         return pickle.dumps(object, protocol=protocol)
-    from UserDict import DictMixin
+    from collections import MutableMapping
 else:
     HIGHEST_PROTOCOL = None
     def _dumps(object, protocol):
         return pickle.dumps(object, bin=protocol)
-    class DictMixin: pass
+    class MutableMapping: pass
 
 from . import db
 

Modified: python/branches/py3k/Lib/dumbdbm.py
==============================================================================
--- python/branches/py3k/Lib/dumbdbm.py	(original)
+++ python/branches/py3k/Lib/dumbdbm.py	Mon Feb  4 21:44:31 2008
@@ -23,13 +23,13 @@
 
 import io as _io
 import os as _os
-import UserDict
+import collections
 
 _BLOCKSIZE = 512
 
 error = IOError                         # For anydbm
 
-class _Database(UserDict.DictMixin):
+class _Database(collections.MutableMapping):
 
     # The on-disk directory and data files can remain in mutually
     # inconsistent states for an arbitrarily long time (see comments

Modified: python/branches/py3k/Lib/shelve.py
==============================================================================
--- python/branches/py3k/Lib/shelve.py	(original)
+++ python/branches/py3k/Lib/shelve.py	Mon Feb  4 21:44:31 2008
@@ -59,12 +59,12 @@
 from pickle import Pickler, Unpickler
 from io import BytesIO
 
-import UserDict
+import collections
 import warnings
 
 __all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
 
-class Shelf(UserDict.DictMixin):
+class Shelf(collections.MutableMapping):
     """Base class for shelf implementations.
 
     This is initialized with a dictionary-like object.
@@ -81,7 +81,7 @@
         self.cache = {}
         self.keyencoding = "utf-8"
 
-    def keys(self):
+    def __iter__(self):
         for k in self.dict.keys():
             yield k.decode(self.keyencoding)
 


More information about the Python-3000-checkins mailing list