Oops -- Lib/Test should be Lib/test, of course!
[python/dscho.git] / Lib / UserDict.py
blob08f3161ca9a344c78e76dfdd263ecc604fc7e191
1 # A more or less complete user-defined wrapper around dictionary objects
3 class UserDict:
4 def __init__(self): self.data = {}
5 def __repr__(self): return repr(self.data)
6 def __cmp__(self, dict):
7 if type(dict) == type(self.data):
8 return cmp(self.data, dict)
9 else:
10 return cmp(self.data, dict.data)
11 def __len__(self): return len(self.data)
12 def __getitem__(self, key): return self.data[key]
13 def __setitem__(self, key, item): self.data[key] = item
14 def __delitem__(self, key): del self.data[key]
15 def clear(self): return self.data.clear()
16 def copy(self):
17 import copy
18 return copy.copy(self)
19 def keys(self): return self.data.keys()
20 def items(self): return self.data.items()
21 def values(self): return self.data.values()
22 def has_key(self, key): return self.data.has_key(key)
23 def update(self, other):
24 if type(other) is type(self.data):
25 self.data.update(other)
26 else:
27 for k, v in other.items():
28 self.data[k] = v
29 def get(self, key, failobj=None):
30 if self.data.has_key(key):
31 return self.data[key]
32 else:
33 return failobj