[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/container/ Fix a
small bug in the order container.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Fri Dec 29 17:07:07 EST 2006
Log message for revision 71677:
Fix a small bug in the order container.
Changed:
U Zope3/trunk/src/zope/app/container/ordered.py
U Zope3/trunk/src/zope/app/container/tests/test_ordered.py
-=-
Modified: Zope3/trunk/src/zope/app/container/ordered.py
===================================================================
--- Zope3/trunk/src/zope/app/container/ordered.py 2006-12-29 16:23:00 UTC (rev 71676)
+++ Zope3/trunk/src/zope/app/container/ordered.py 2006-12-29 22:07:05 UTC (rev 71677)
@@ -191,17 +191,21 @@
bad = True
else:
bad = True
- if bad:
+ if bad:
raise TypeError("'%s' is invalid, the key must be an "
"ascii or unicode string" % key)
if len(key) == 0:
raise ValueError("The key cannot be an empty string")
- setitem(self, self._data.__setitem__, key, object)
-
+ # We have to first update the order, so that the item is available,
+ # otherwise most API functions will lie about their available values
+ # when an event subscriber tries to do something with the container.
if not existed:
self._order.append(key)
+ # This function creates a lot of events that other code listens to.
+ setitem(self, self._data.__setitem__, key, object)
+
return key
def __delitem__(self, key):
Modified: Zope3/trunk/src/zope/app/container/tests/test_ordered.py
===================================================================
--- Zope3/trunk/src/zope/app/container/tests/test_ordered.py 2006-12-29 16:23:00 UTC (rev 71676)
+++ Zope3/trunk/src/zope/app/container/tests/test_ordered.py 2006-12-29 22:07:05 UTC (rev 71677)
@@ -60,6 +60,35 @@
>>> setup.placefulTearDown()
"""
+def test_all_items_available_at_object_added_event():
+ """
+ Prepare the setup::
+
+ >>> root = setup.placefulSetUp(site=True)
+
+ Now register an event subscriber to object added events.
+
+ >>> import zope.component
+ >>> from zope.app.container import interfaces
+
+ >>> @zope.component.adapter(interfaces.IObjectAddedEvent)
+ ... def printContainerKeys(event):
+ ... print event.newParent.keys()
+
+ >>> zope.component.provideHandler(printContainerKeys)
+
+ Now we are adding an object to the container.
+
+ >>> from zope.app.container.ordered import OrderedContainer
+ >>> oc = OrderedContainer()
+ >>> oc['foo'] = 'FOO'
+ ['foo']
+
+ Finally, tear down::
+
+ >>> setup.placefulTearDown()
+ """
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(DocTestSuite("zope.app.container.ordered",
More information about the Zope3-Checkins
mailing list