summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2011-07-16 14:51:11 -0500
committerMichael Merickel <michael@merickel.org>2011-07-16 18:29:13 -0500
commit01c4f3e8253b708df2266e6847ffc649603eec02 (patch)
tree9a5c73cab53fef2ada95b3353a550af48801fbc7
parent795ddb42a12777f12fc5605fa908106a8d65cffd (diff)
downloadpyramid-01c4f3e8253b708df2266e6847ffc649603eec02.tar.gz
pyramid-01c4f3e8253b708df2266e6847ffc649603eec02.tar.bz2
pyramid-01c4f3e8253b708df2266e6847ffc649603eec02.zip
Modified the order of the WeakOrderedSet to remember the most recent.
-rw-r--r--pyramid/util.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/pyramid/util.py b/pyramid/util.py
index a4b69ed96..7fd1b0dc6 100644
--- a/pyramid/util.py
+++ b/pyramid/util.py
@@ -151,6 +151,17 @@ class WeakOrderedSet(object):
The values may be iterated over or the last item added may be
accessed via the ``last`` property.
+
+ If items are added more than once, the most recent addition will
+ be remembered in the order:
+
+ order = WeakOrderedSet()
+ order.add('1')
+ order.add('2')
+ order.add('1')
+
+ list(order) == ['2', '1']
+ order.last == '1'
"""
def __init__(self):
@@ -161,6 +172,8 @@ class WeakOrderedSet(object):
""" Add an item to the set."""
oid = id(item)
if oid in self._items:
+ self._order.remove(oid)
+ self._order.append(oid)
return
ref = weakref.ref(item, lambda x: self.remove(item))
self._items[oid] = ref