summaryrefslogtreecommitdiffstats
path: root/Lib/dos-8x3/userdict.py
blob: 08f3161ca9a344c78e76dfdd263ecc604fc7e191 (plain)
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
# A more or less complete user-defined wrapper around dictionary objects

class UserDict:
    def __init__(self): self.data = {}
    def __repr__(self): return repr(self.data)
    def __cmp__(self, dict):
        if type(dict) == type(self.data):
            return cmp(self.data, dict)
        else:
            return cmp(self.data, dict.data)
    def __len__(self): return len(self.data)
    def __getitem__(self, key): return self.data[key]
    def __setitem__(self, key, item): self.data[key] = item
    def __delitem__(self, key): del self.data[key]
    def clear(self): return self.data.clear()
    def copy(self):
        import copy
        return copy.copy(self)
    def keys(self): return self.data.keys()
    def items(self): return self.data.items()
    def values(self): return self.data.values()
    def has_key(self, key): return self.data.has_key(key)
    def update(self, other):
        if type(other) is type(self.data):
            self.data.update(other)
        else:
            for k, v in other.items():
                self.data[k] = v
    def get(self, key, failobj=None):
        if self.data.has_key(key):
            return self.data[key]
        else:
            return failobj