Show More
@@ -567,54 +567,14 b' def cachefunc(func):' | |||
|
567 | 567 | |
|
568 | 568 | return f |
|
569 | 569 | |
|
570 | class sortdict(dict): | |
|
570 | class sortdict(collections.OrderedDict): | |
|
571 | 571 | '''a simple sorted dictionary''' |
|
572 |
def __ |
|
|
573 | self._list = [] | |
|
574 | if data: | |
|
575 | self.update(data) | |
|
572 | def __setitem__(self, key, value): | |
|
573 | if key in self: | |
|
574 | del self[key] | |
|
575 | super(sortdict, self).__setitem__(key, value) | |
|
576 | 576 | def copy(self): |
|
577 | 577 | return sortdict(self) |
|
578 | def __setitem__(self, key, val): | |
|
579 | if key in self: | |
|
580 | self._list.remove(key) | |
|
581 | self._list.append(key) | |
|
582 | dict.__setitem__(self, key, val) | |
|
583 | def __iter__(self): | |
|
584 | return self._list.__iter__() | |
|
585 | def update(self, src): | |
|
586 | if isinstance(src, dict): | |
|
587 | src = src.iteritems() | |
|
588 | for k, v in src: | |
|
589 | self[k] = v | |
|
590 | def clear(self): | |
|
591 | dict.clear(self) | |
|
592 | self._list = [] | |
|
593 | def items(self): | |
|
594 | return [(k, self[k]) for k in self._list] | |
|
595 | def __delitem__(self, key): | |
|
596 | dict.__delitem__(self, key) | |
|
597 | self._list.remove(key) | |
|
598 | def pop(self, key, *args, **kwargs): | |
|
599 | try: | |
|
600 | self._list.remove(key) | |
|
601 | except ValueError: | |
|
602 | pass | |
|
603 | return dict.pop(self, key, *args, **kwargs) | |
|
604 | def keys(self): | |
|
605 | return self._list[:] | |
|
606 | def iterkeys(self): | |
|
607 | return self._list.__iter__() | |
|
608 | def iteritems(self): | |
|
609 | for k in self._list: | |
|
610 | yield k, self[k] | |
|
611 | def insert(self, index, key, val): | |
|
612 | self._list.insert(index, key) | |
|
613 | dict.__setitem__(self, key, val) | |
|
614 | def __repr__(self): | |
|
615 | if not self: | |
|
616 | return '%s()' % self.__class__.__name__ | |
|
617 | return '%s(%r)' % (self.__class__.__name__, self.items()) | |
|
618 | 578 | |
|
619 | 579 | class _lrucachenode(object): |
|
620 | 580 | """A node in a doubly linked list. |
General Comments 0
You need to be logged in to leave comments.
Login now