1 """Drop-in replacement for collections.OrderedDict by Raymond Hettinger
3 http://code.activestate.com/recipes/576693/
6 from UserDict
import DictMixin
13 raise TypeError(
'expected at most 1 arguments, got %d' % len(args))
16 except AttributeError:
22 end += [
None, end, end]
30 curr[2] = end[1] = self.
__map[key] = [key, curr, end]
31 dict.__setitem__(self, key, value)
34 dict.__delitem__(self, key)
35 key, prev, next = self.
__map.
pop(key)
42 while curr
is not end:
49 while curr
is not end:
55 raise KeyError(
'dictionary is empty')
56 key = reversed(self).next()
if last
else iter(self).next()
61 items = [[k, self[k]]
for k
in self]
64 inst_dict = vars(self).
copy()
67 return (self.__class__, (items,), inst_dict)
68 return self.__class__, (items,)
73 setdefault = DictMixin.setdefault
74 update = DictMixin.update
76 values = DictMixin.values
77 items = DictMixin.items
78 iterkeys = DictMixin.iterkeys
79 itervalues = DictMixin.itervalues
80 iteritems = DictMixin.iteritems
84 return '%s()' % (self.__class__.__name__,)
85 return '%s(%r)' % (self.__class__.__name__, self.
items())
88 return self.__class__(self)
98 if isinstance(other, OrderedDict):
99 return len(self) == len(other)
and \
100 all(p == q
for p, q
in zip(self.
items(), other.items()))
101 return dict.__eq__(self, other)
104 return not self == other