summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-12-08 21:06:39 +0000
committerZac Medico <zmedico@gentoo.org>2009-12-08 21:06:39 +0000
commit0a993bf71d0e4ff87dd85b7226e1662c70a53e08 (patch)
tree43be37dce332562ffd51cd8def477d26503e684d
parentfe39ff5c9c99b47706826308e7edb8274ca5050b (diff)
downloadportage-0a993bf71d0e4ff87dd85b7226e1662c70a53e08.tar.gz
portage-0a993bf71d0e4ff87dd85b7226e1662c70a53e08.tar.bz2
portage-0a993bf71d0e4ff87dd85b7226e1662c70a53e08.zip
Add OrderedDict class.
svn path=/main/trunk/; revision=14967
-rw-r--r--pym/portage/cache/mappings.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/pym/portage/cache/mappings.py b/pym/portage/cache/mappings.py
index ed6e19ddd..2e24a7a8a 100644
--- a/pym/portage/cache/mappings.py
+++ b/pym/portage/cache/mappings.py
@@ -188,6 +188,32 @@ class UserDict(MutableMapping):
if sys.hexversion >= 0x3000000:
keys = __iter__
+class OrderedDict(UserDict):
+
+ def __init__(self, *args, **kwargs):
+ self._order = []
+ UserDict.__init__(self, *args, **kwargs)
+
+ def __iter__(self):
+ return iter(self._order)
+
+ def __setitem__(self, key, item):
+ if key in self:
+ self._order.remove(key)
+ UserDict.__setitem__(self, key, item)
+ self._order.append(key)
+
+ def __delitem__(self, key):
+ UserDict.__delitem__(self, key)
+ self._order.remove(key)
+
+ def clear(self):
+ UserDict.clear(self)
+ del self._order[:]
+
+ if sys.hexversion >= 0x3000000:
+ keys = __iter__
+
class ProtectedDict(MutableMapping):
"""
given an initial dict, this wraps that dict storing changes in a secondary dict, protecting