* [gentoo-commits] portage r15001 - main/branches/2.1.7/pym/portage/cache
@ 2009-12-10 1:03 Zac Medico (zmedico)
0 siblings, 0 replies; only message in thread
From: Zac Medico (zmedico) @ 2009-12-10 1:03 UTC (permalink / raw
To: gentoo-commits
Author: zmedico
Date: 2009-12-10 01:03:20 +0000 (Thu, 10 Dec 2009)
New Revision: 15001
Modified:
main/branches/2.1.7/pym/portage/cache/mappings.py
Log:
Add OrderedDict class. (trunk r14967)
Modified: main/branches/2.1.7/pym/portage/cache/mappings.py
===================================================================
--- main/branches/2.1.7/pym/portage/cache/mappings.py 2009-12-10 01:03:00 UTC (rev 15000)
+++ main/branches/2.1.7/pym/portage/cache/mappings.py 2009-12-10 01:03:20 UTC (rev 15001)
@@ -188,6 +188,32 @@
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-12-10 1:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-10 1:03 [gentoo-commits] portage r15001 - main/branches/2.1.7/pym/portage/cache Zac Medico (zmedico)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox