mirror of
https://github.com/python/cpython
synced 2024-09-15 21:50:10 +00:00
Start replacing UserDict.DictMixin with collections.MutableMapping (the bsddb modules are next).
This commit is contained in:
parent
15ebc88d87
commit
b9da9bc0a0
|
@ -378,6 +378,11 @@ def items(self):
|
||||||
def values(self):
|
def values(self):
|
||||||
return ValuesView(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):
|
class MappingView(metaclass=ABCMeta):
|
||||||
|
|
||||||
|
@ -485,6 +490,13 @@ def update(self, other=(), **kwds):
|
||||||
for key, value in kwds.items():
|
for key, value in kwds.items():
|
||||||
self[key] = value
|
self[key] = value
|
||||||
|
|
||||||
|
def setdefault(self, key, default=None):
|
||||||
|
try:
|
||||||
|
return self[key]
|
||||||
|
except KeyError:
|
||||||
|
self[key] = default
|
||||||
|
return default
|
||||||
|
|
||||||
MutableMapping.register(dict)
|
MutableMapping.register(dict)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -38,12 +38,12 @@
|
||||||
HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
|
HIGHEST_PROTOCOL = pickle.HIGHEST_PROTOCOL
|
||||||
def _dumps(object, protocol):
|
def _dumps(object, protocol):
|
||||||
return pickle.dumps(object, protocol=protocol)
|
return pickle.dumps(object, protocol=protocol)
|
||||||
from UserDict import DictMixin
|
from collections import MutableMapping
|
||||||
else:
|
else:
|
||||||
HIGHEST_PROTOCOL = None
|
HIGHEST_PROTOCOL = None
|
||||||
def _dumps(object, protocol):
|
def _dumps(object, protocol):
|
||||||
return pickle.dumps(object, bin=protocol)
|
return pickle.dumps(object, bin=protocol)
|
||||||
class DictMixin: pass
|
class MutableMapping: pass
|
||||||
|
|
||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
|
|
|
@ -23,13 +23,13 @@
|
||||||
|
|
||||||
import io as _io
|
import io as _io
|
||||||
import os as _os
|
import os as _os
|
||||||
import UserDict
|
import collections
|
||||||
|
|
||||||
_BLOCKSIZE = 512
|
_BLOCKSIZE = 512
|
||||||
|
|
||||||
error = IOError # For anydbm
|
error = IOError # For anydbm
|
||||||
|
|
||||||
class _Database(UserDict.DictMixin):
|
class _Database(collections.MutableMapping):
|
||||||
|
|
||||||
# The on-disk directory and data files can remain in mutually
|
# The on-disk directory and data files can remain in mutually
|
||||||
# inconsistent states for an arbitrarily long time (see comments
|
# inconsistent states for an arbitrarily long time (see comments
|
||||||
|
|
|
@ -59,12 +59,12 @@
|
||||||
from pickle import Pickler, Unpickler
|
from pickle import Pickler, Unpickler
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import UserDict
|
import collections
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
__all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
|
__all__ = ["Shelf","BsdDbShelf","DbfilenameShelf","open"]
|
||||||
|
|
||||||
class Shelf(UserDict.DictMixin):
|
class Shelf(collections.MutableMapping):
|
||||||
"""Base class for shelf implementations.
|
"""Base class for shelf implementations.
|
||||||
|
|
||||||
This is initialized with a dictionary-like object.
|
This is initialized with a dictionary-like object.
|
||||||
|
@ -81,7 +81,7 @@ def __init__(self, dict, protocol=None, writeback=False,
|
||||||
self.cache = {}
|
self.cache = {}
|
||||||
self.keyencoding = "utf-8"
|
self.keyencoding = "utf-8"
|
||||||
|
|
||||||
def keys(self):
|
def __iter__(self):
|
||||||
for k in self.dict.keys():
|
for k in self.dict.keys():
|
||||||
yield k.decode(self.keyencoding)
|
yield k.decode(self.keyencoding)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue