diff options
-rw-r--r-- | Lib/_abcoll.py | 12 | ||||
-rw-r--r-- | Lib/bsddb/dbshelve.py | 4 | ||||
-rw-r--r-- | Lib/dumbdbm.py | 4 | ||||
-rw-r--r-- | Lib/shelve.py | 6 |
4 files changed, 19 insertions, 7 deletions
diff --git a/Lib/_abcoll.py b/Lib/_abcoll.py index 005f437..de6e6f8 100644 --- a/Lib/_abcoll.py +++ b/Lib/_abcoll.py @@ -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) diff --git a/Lib/bsddb/dbshelve.py b/Lib/bsddb/dbshelve.py index 8264f2d..a2d7bb7 100644 --- a/Lib/bsddb/dbshelve.py +++ b/Lib/bsddb/dbshelve.py @@ -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 diff --git a/Lib/dumbdbm.py b/Lib/dumbdbm.py index e44e1f5..8d58f87 100644 --- a/Lib/dumbdbm.py +++ b/Lib/dumbdbm.py @@ -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 diff --git a/Lib/shelve.py b/Lib/shelve.py index 586d253..67878db 100644 --- a/Lib/shelve.py +++ b/Lib/shelve.py @@ -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) |