1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from UserDict import DictMixin
27
29 if len(args) > 1:
30 raise TypeError('expected at most 1 arguments, got %d' % len(args))
31 try:
32 self.__end
33 except AttributeError:
34 self.clear()
35 self.update(*args, **kwds)
36
38 self.__end = end = []
39 end += [None, end, end]
40 self.__map = {}
41 dict.clear(self)
42
44 if key not in self:
45 end = self.__end
46 curr = end[1]
47 curr[2] = end[1] = self.__map[key] = [key, curr, end]
48 dict.__setitem__(self, key, value)
49
55
57 end = self.__end
58 curr = end[2]
59 while curr is not end:
60 yield curr[0]
61 curr = curr[2]
62
64 end = self.__end
65 curr = end[1]
66 while curr is not end:
67 yield curr[0]
68 curr = curr[1]
69
71 if not self:
72 raise KeyError('dictionary is empty')
73 if last:
74 key = reversed(self).next()
75 else:
76 key = iter(self).next()
77 value = self.pop(key)
78 return key, value
79
81 items = [[k, self[k]] for k in self]
82 tmp = self.__map, self.__end
83 del self.__map, self.__end
84 inst_dict = vars(self).copy()
85 self.__map, self.__end = tmp
86 if inst_dict:
87 return (self.__class__, (items,), inst_dict)
88 return self.__class__, (items,)
89
92
93 setdefault = DictMixin.setdefault
94 update = DictMixin.update
95 pop = DictMixin.pop
96 values = DictMixin.values
97 items = DictMixin.items
98 iterkeys = DictMixin.iterkeys
99 itervalues = DictMixin.itervalues
100 iteritems = DictMixin.iteritems
101
103 if not self:
104 return '%s()' % (self.__class__.__name__,)
105 return '%s(%r)' % (self.__class__.__name__, self.items())
106
108 return self.__class__(self)
109
110 @classmethod
111 - def fromkeys(cls, iterable, value=None):
112 d = cls()
113 for key in iterable:
114 d[key] = value
115 return d
116
126
128 return not self == other
129