mirror of
https://github.com/python/cpython.git
synced 2025-10-02 05:12:23 +00:00
Remove the old UserDict module.
This commit is contained in:
parent
f80680d8cd
commit
0fc8351f64
2 changed files with 1 additions and 82 deletions
|
@ -1,81 +0,0 @@
|
||||||
"""A more or less complete user-defined wrapper around dictionary objects."""
|
|
||||||
|
|
||||||
class UserDict:
|
|
||||||
def __init__(self, dict=None, **kwargs):
|
|
||||||
self.data = {}
|
|
||||||
if dict is not None:
|
|
||||||
self.update(dict)
|
|
||||||
if len(kwargs):
|
|
||||||
self.update(kwargs)
|
|
||||||
def __repr__(self): return repr(self.data)
|
|
||||||
def __eq__(self, dict):
|
|
||||||
if isinstance(dict, UserDict):
|
|
||||||
return self.data == dict.data
|
|
||||||
else:
|
|
||||||
return self.data == dict
|
|
||||||
def __ne__(self, dict):
|
|
||||||
if isinstance(dict, UserDict):
|
|
||||||
return self.data != dict.data
|
|
||||||
else:
|
|
||||||
return self.data != dict
|
|
||||||
def __len__(self): return len(self.data)
|
|
||||||
def __getitem__(self, key):
|
|
||||||
if key in self.data:
|
|
||||||
return self.data[key]
|
|
||||||
if hasattr(self.__class__, "__missing__"):
|
|
||||||
return self.__class__.__missing__(self, key)
|
|
||||||
raise KeyError(key)
|
|
||||||
def __setitem__(self, key, item): self.data[key] = item
|
|
||||||
def __delitem__(self, key): del self.data[key]
|
|
||||||
def clear(self): self.data.clear()
|
|
||||||
def copy(self):
|
|
||||||
if self.__class__ is UserDict:
|
|
||||||
return UserDict(self.data.copy())
|
|
||||||
import copy
|
|
||||||
data = self.data
|
|
||||||
try:
|
|
||||||
self.data = {}
|
|
||||||
c = copy.copy(self)
|
|
||||||
finally:
|
|
||||||
self.data = data
|
|
||||||
c.update(self)
|
|
||||||
return c
|
|
||||||
def keys(self): return self.data.keys()
|
|
||||||
def items(self): return self.data.items()
|
|
||||||
def values(self): return self.data.values()
|
|
||||||
def update(self, dict=None, **kwargs):
|
|
||||||
if dict is None:
|
|
||||||
pass
|
|
||||||
elif isinstance(dict, UserDict):
|
|
||||||
self.data.update(dict.data)
|
|
||||||
elif isinstance(dict, type({})) or not hasattr(dict, 'items'):
|
|
||||||
self.data.update(dict)
|
|
||||||
else:
|
|
||||||
for k, v in dict.items():
|
|
||||||
self[k] = v
|
|
||||||
if len(kwargs):
|
|
||||||
self.data.update(kwargs)
|
|
||||||
def get(self, key, failobj=None):
|
|
||||||
if key not in self:
|
|
||||||
return failobj
|
|
||||||
return self[key]
|
|
||||||
def setdefault(self, key, failobj=None):
|
|
||||||
if key not in self:
|
|
||||||
self[key] = failobj
|
|
||||||
return self[key]
|
|
||||||
def pop(self, key, *args):
|
|
||||||
return self.data.pop(key, *args)
|
|
||||||
def popitem(self):
|
|
||||||
return self.data.popitem()
|
|
||||||
def __contains__(self, key):
|
|
||||||
return key in self.data
|
|
||||||
@classmethod
|
|
||||||
def fromkeys(cls, iterable, value=None):
|
|
||||||
d = cls()
|
|
||||||
for key in iterable:
|
|
||||||
d[key] = value
|
|
||||||
return d
|
|
||||||
|
|
||||||
class IterableUserDict(UserDict):
|
|
||||||
def __iter__(self):
|
|
||||||
return iter(self.data)
|
|
|
@ -75,7 +75,7 @@ Library
|
||||||
|
|
||||||
- Created new UserDict class in collections module. This one inherits from and
|
- Created new UserDict class in collections module. This one inherits from and
|
||||||
complies with the MutableMapping ABC.
|
complies with the MutableMapping ABC.
|
||||||
XXX still need to covert old UserDict based tests and eliminate the old UserDict module.
|
XXX still need to move docs
|
||||||
|
|
||||||
- Removed UserDict.DictMixin. Replaced all its uses with collections.MutableMapping.
|
- Removed UserDict.DictMixin. Replaced all its uses with collections.MutableMapping.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue