]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Start replacing UserDict.DictMixin with collections.MutableMapping (the bsddb modules...
authorRaymond Hettinger <python@rcn.com>
Mon, 4 Feb 2008 20:44:31 +0000 (20:44 +0000)
committerRaymond Hettinger <python@rcn.com>
Mon, 4 Feb 2008 20:44:31 +0000 (20:44 +0000)
Lib/_abcoll.py
Lib/bsddb/dbshelve.py
Lib/dumbdbm.py
Lib/shelve.py

index 005f437860a4e9904535c8bee0cbd2248fbbdacb..de6e6f8d1f2b1270219d96c1383ff3401f8095f9 100644 (file)
@@ -378,6 +378,11 @@ class Mapping(metaclass=ABCMeta):
     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 @@ class MutableMapping(Mapping):
         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)
 
 
index 8264f2d8121aa0a656d43bd2891862257601e27f..a2d7bb79180d4f2b862704b54aac71f6a40d14bd 100644 (file)
@@ -38,12 +38,12 @@ if sys.version_info[:3] >= (2, 3, 0):
     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
 
index e44e1f5fd500d5270b645b029c93f838dd265d95..8d58f8780abcb0cd123f540ab211e33ab2c8b61e 100644 (file)
@@ -23,13 +23,13 @@ is read when the database is opened, and some updates rewrite the whole index)
 
 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
index 586d2535d840a861669da47ac812fa5620f1e3ba..67878db45f53e0a084b3602008ae538f09c375d6 100644 (file)
@@ -59,12 +59,12 @@ the persistent dictionary on disk, if feasible).
 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 @@ class Shelf(UserDict.DictMixin):
         self.cache = {}
         self.keyencoding = "utf-8"
 
-    def keys(self):
+    def __iter__(self):
         for k in self.dict.keys():
             yield k.decode(self.keyencoding)