summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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