/usr/lib/python2.7/dist-packages/Scientific/DictWithDefault.py is in python-scientific 2.9.4-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | # A dictionary with default values for non-existing entries
"""
Dictionary with default values
Note: this module has become obsolete by the introduction of the get method
for standard Python dictionaries. It is maintained only in order not to
break old code that uses it.
"""
import UserDict, copy
class DictWithDefault(UserDict.UserDict):
"""
Dictionary with default values
Instances of this class act like standard Python dictionaries,
except that they return a *copy* of |default| for a key that
has no associated value.
"""
def __init__(self, default):
"""
@param default: the default value that is returned for a key that
has no associated value
"""
self.data = {}
self.default = default
UserDict.UserDict.__init__(self)
def __getitem__(self, key):
"""
@param key: the key whose associated value is requested
@returns: the associated value. If none is defined, the return
value is a copy of the default value.
"""
try:
item = self.data[key]
except KeyError:
item = copy.copy(self.default)
self.data[key] = item
return item
def __delitem__(self, key):
try:
del self.data[key]
except KeyError:
pass
|