[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/ Fixed a bug:
Jim Fulton
jim at zope.com
Wed Nov 10 18:13:39 EST 2004
Log message for revision 28425:
Fixed a bug:
"The unique id utility's subscribers aren't set up to get the
proper notifications. Unfortunately, the uniqueid utility also defines
an event framework for notifying catalogs that reflects a lack of
understanding of how location events are handled."
Changed:
U Zope3/trunk/src/zope/app/catalog/catalog.py
U Zope3/trunk/src/zope/app/catalog/tests.py
U Zope3/trunk/src/zope/app/uniqueid/__init__.py
A Zope3/trunk/src/zope/app/uniqueid/browser/ftests.py
A Zope3/trunk/src/zope/app/uniqueid/browser/tracking.txt
U Zope3/trunk/src/zope/app/uniqueid/configure.zcml
U Zope3/trunk/src/zope/app/uniqueid/interfaces.py
U Zope3/trunk/src/zope/app/uniqueid/tests.py
-=-
Modified: Zope3/trunk/src/zope/app/catalog/catalog.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/catalog.py 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/catalog/catalog.py 2004-11-10 23:13:39 UTC (rev 28425)
@@ -124,7 +124,7 @@
def indexDocSubscriber(event):
"""A subscriber to UniqueIdAddedEvent"""
for cat in zapi.getAllUtilitiesRegisteredFor(ICatalog):
- ob = event.original_event.object
+ ob = event.object
id = zapi.getUtility(IUniqueIdUtility, context=cat).getId(ob)
cat.index_doc(id, ob)
@@ -141,7 +141,7 @@
def unindexDocSubscriber(event):
"""A subscriber to UniqueIdRemovedEvent"""
for cat in zapi.getAllUtilitiesRegisteredFor(ICatalog):
- ob = event.original_event.object
+ ob = event.object
id = zapi.getUtility(IUniqueIdUtility, context=cat).queryId(ob)
if id is not None:
cat.unindex_doc(id)
Modified: Zope3/trunk/src/zope/app/catalog/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/catalog/tests.py 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/catalog/tests.py 2004-11-10 23:13:39 UTC (rev 28425)
@@ -242,9 +242,10 @@
from zope.app.uniqueid.interfaces import UniqueIdAddedEvent
ob = Stub()
+ ob2 = Stub()
id = self.utility.register(ob)
- indexDocSubscriber(UniqueIdAddedEvent(ObjectAddedEvent(ob)))
+ indexDocSubscriber(UniqueIdAddedEvent(ob, ObjectAddedEvent(ob2)))
self.assertEqual(self.cat.regs, [(id, ob)])
self.assertEqual(self.cat.unregs, [])
@@ -274,13 +275,16 @@
ob = Stub()
ob2 = Stub()
+ ob3 = Stub()
id = self.utility.register(ob)
- unindexDocSubscriber(UniqueIdRemovedEvent(ObjectRemovedEvent(ob2)))
+ unindexDocSubscriber(
+ UniqueIdRemovedEvent(ob2, ObjectRemovedEvent(ob3)))
self.assertEqual(self.cat.unregs, [])
self.assertEqual(self.cat.regs, [])
- unindexDocSubscriber(UniqueIdRemovedEvent(ObjectRemovedEvent(ob)))
+ unindexDocSubscriber(
+ UniqueIdRemovedEvent(ob, ObjectRemovedEvent(ob3)))
self.assertEqual(self.cat.unregs, [id])
self.assertEqual(self.cat.regs, [])
Modified: Zope3/trunk/src/zope/app/uniqueid/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/__init__.py 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/uniqueid/__init__.py 2004-11-10 23:13:39 UTC (rev 28425)
@@ -150,7 +150,7 @@
return cur._p_jar
-def removeUniqueIdSubscriber(event):
+def removeUniqueIdSubscriber(ob, event):
"""A subscriber to ObjectRemovedEvent
Removes the unique ids registered for the object in all the unique
@@ -158,21 +158,21 @@
"""
# Notify the catalogs that this object is about to be removed.
- notify(UniqueIdRemovedEvent(event))
+ notify(UniqueIdRemovedEvent(ob, event))
for utility in zapi.getAllUtilitiesRegisteredFor(IUniqueIdUtility):
try:
- utility.unregister(event.object)
+ utility.unregister(ob)
except KeyError:
pass
-def addUniqueIdSubscriber(event):
+def addUniqueIdSubscriber(ob, event):
"""A subscriber to ObjectAddedEvent
Registers the object added in all unique id utilities and fires
an event for the catalogs.
"""
for utility in zapi.getAllUtilitiesRegisteredFor(IUniqueIdUtility):
- utility.register(event.object)
+ utility.register(ob)
- notify(UniqueIdAddedEvent(event))
+ notify(UniqueIdAddedEvent(ob, event))
Added: Zope3/trunk/src/zope/app/uniqueid/browser/ftests.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/browser/ftests.py 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/uniqueid/browser/ftests.py 2004-11-10 23:13:39 UTC (rev 28425)
@@ -0,0 +1,28 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""XXX short summary goes here.
+
+$Id$
+"""
+import unittest
+
+def test_suite():
+ from zope.app.tests import functional
+ return unittest.TestSuite((
+ functional.FunctionalDocFileSuite('tracking.txt'),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
Property changes on: Zope3/trunk/src/zope/app/uniqueid/browser/ftests.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: Zope3/trunk/src/zope/app/uniqueid/browser/tracking.txt
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/browser/tracking.txt 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/uniqueid/browser/tracking.txt 2004-11-10 23:13:39 UTC (rev 28425)
@@ -0,0 +1,137 @@
+Tracking Object Additions, Deletions, and Moves
+===============================================
+
+Unique ID utilities track object add moves. Let's look at an
+example. First, we'll create a unique Id utility:
+
+ (The first request is a bit weird. It is part of the current
+ tools UI. It arranges for a tools site-management folder to be
+ created. We really need to rethink how we manage TTW utilities.)
+
+ >>> print http(r"""
+ ... GET /++etc++site/AddIUniqueIdUtilityTool HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Referer: http://localhost:8081/++etc++site/@@manageIUniqueIdUtilityTool.html
+ ... """)
+ HTTP/1.1 200 Ok
+ ...
+
+ >>> print http(r"""
+ ... POST /++etc++site/AddIUniqueIdUtilityTool/action.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 69
+ ... Content-Type: application/x-www-form-urlencoded
+ ... Referer: http://localhost:8081/++etc++site/AddIUniqueIdUtilityTool
+ ...
+ ... type_name=BrowserAdd__zope.app.uniqueid.UniqueIdUtility&id=&add=+Add+""")
+ HTTP/1.1 303 See Other
+ ...
+ Location: ../@@manageIUniqueIdUtilityTool.html
+ ...
+
+Now, we'll add a few folders:
+
+ >>> print http(r"""
+ ... POST /@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 64
+ ... Content-Type: application/x-www-form-urlencoded
+ ...
+ ... type_name=BrowserAdd__zope.app.folder.folder.Folder&new_value=f1""")
+ HTTP/1.1 303 See Other
+ ...
+
+ >>> print http(r"""
+ ... POST /f1/@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 64
+ ... Content-Type: application/x-www-form-urlencoded
+ ...
+ ... type_name=BrowserAdd__zope.app.folder.folder.Folder&new_value=f1""")
+ HTTP/1.1 303 See Other
+ ...
+
+ >>> print http(r"""
+ ... POST /f1/@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 64
+ ... Content-Type: application/x-www-form-urlencoded
+ ...
+ ... type_name=BrowserAdd__zope.app.folder.folder.Folder&new_value=f2""")
+ HTTP/1.1 303 See Other
+ ...
+
+ >>> print http(r"""
+ ... POST /f1/f1/@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 64
+ ... Content-Type: application/x-www-form-urlencoded
+ ...
+ ... type_name=BrowserAdd__zope.app.folder.folder.Folder&new_value=f1""")
+ HTTP/1.1 303 See Other
+ ...
+
+Now, if we look at the index page for the unique id utility, we'll see
+the objects we added:
+
+ >>> print http(r"""
+ ... GET /++etc++site/tools/UniqueIdUtility/@@index.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Referer: http://localhost:8081/++etc++site/tools/@@contents.html
+ ... """)
+ HTTP/1.1 200 Ok
+ ...4 objects...
+ .../f1...
+ .../f1/f1...
+ .../f1/f2...
+ .../f1/f1/f1...
+
+If we move the top object:
+
+ >>> print http(r"""
+ ... POST /@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 40
+ ... Content-Type: application/x-www-form-urlencoded
+ ... Referer: http://localhost:8081/@@contents.html
+ ...
+ ... new_value%3Alist=f2&rename_ids%3Alist=f1""")
+ HTTP/1.1 303 See Other
+ ...
+
+We'll see that reflected in the utility:
+
+ >>> print http(r"""
+ ... GET /++etc++site/tools/UniqueIdUtility/@@index.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Referer: http://localhost:8081/++etc++site/tools/@@contents.html
+ ... """)
+ HTTP/1.1 200 Ok
+ ...4 objects...
+ .../f2...
+ .../f2/f1...
+ .../f2/f2...
+ .../f2/f1/f1...
+
+And if we delete the top object:
+
+ >>> print http(r"""
+ ... POST /@@contents.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 44
+ ... Content-Type: application/x-www-form-urlencoded
+ ... Referer: http://localhost:8081/@@contents.html
+ ...
+ ... ids%3Alist=f2&container_delete_button=Delete""")
+ HTTP/1.1 303 See Other
+ ...
+
+all of the objects will go away:
+
+ >>> print http(r"""
+ ... GET /++etc++site/tools/UniqueIdUtility/@@index.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Referer: http://localhost:8081/++etc++site/tools/@@contents.html
+ ... """)
+ HTTP/1.1 200 Ok
+ ...0 objects...
Property changes on: Zope3/trunk/src/zope/app/uniqueid/browser/tracking.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/uniqueid/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/configure.zcml 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/uniqueid/configure.zcml 2004-11-10 23:13:39 UTC (rev 28425)
@@ -44,12 +44,14 @@
<subscriber
factory=".removeUniqueIdSubscriber"
- for="zope.app.container.interfaces.IObjectRemovedEvent"
+ for="zope.app.location.interfaces.ILocation
+ zope.app.container.interfaces.IObjectRemovedEvent"
/>
<subscriber
factory=".addUniqueIdSubscriber"
- for="zope.app.container.interfaces.IObjectAddedEvent"
+ for="zope.app.location.interfaces.ILocation
+ zope.app.container.interfaces.IObjectAddedEvent"
/>
<!-- Views -->
Modified: Zope3/trunk/src/zope/app/uniqueid/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/interfaces.py 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/uniqueid/interfaces.py 2004-11-10 23:13:39 UTC (rev 28425)
@@ -73,29 +73,38 @@
class IUniqueIdRemovedEvent(Interface):
- """The event which is published before the unique id is removed
- from the utility so that the catalogs can unindex the object.
+ """A unique id will be removed
+
+ The event is published before the unique id is removed
+ from the utility so that the indexing objects can unindex the object.
"""
- original_event = Attribute(
- """The IObjectRemoveEvent related to this event""")
+ object = Attribute("The object being removed")
+ original_event = Attribute("The IObjectRemoveEvent related to this event")
-class UniqueIdRemovedEvent(object):
+
+class UniqueIdRemovedEvent:
"""The event which is published before the unique id is removed
from the utility so that the catalogs can unindex the object.
"""
implements(IUniqueIdRemovedEvent)
- def __init__(self, event):
+ def __init__(self, object, event):
+ self.object = object
self.original_event = event
class IUniqueIdAddedEvent(Interface):
- """The event which gets sent when an object is registered in a
+ """A unique id has been added
+
+ The event gets sent when an object is registered in a
unique id utility.
"""
+
+ object = Attribute("The object being added")
+
original_event = Attribute("The ObjectAddedEvent related to this event")
@@ -103,6 +112,9 @@
"""The event which gets sent when an object is registered in a
unique id utility.
"""
+
implements(IUniqueIdAddedEvent)
- def __init__(self, event):
+
+ def __init__(self, object, event):
+ self.object = object
self.original_event = event
Modified: Zope3/trunk/src/zope/app/uniqueid/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/uniqueid/tests.py 2004-11-10 21:44:47 UTC (rev 28424)
+++ Zope3/trunk/src/zope/app/uniqueid/tests.py 2004-11-10 23:13:39 UTC (rev 28425)
@@ -226,6 +226,7 @@
from zope.app.uniqueid import removeUniqueIdSubscriber
from zope.app.container.contained import ObjectRemovedEvent
from zope.app.uniqueid.interfaces import IUniqueIdRemovedEvent
+ parent_folder = self.root['folder1']['folder1_1']
folder = self.root['folder1']['folder1_1']['folder1_1_1']
id = self.utility.register(folder)
id1 = self.utility1.register(folder)
@@ -238,18 +239,20 @@
# This should unregister the object in all utilities, not just the
# nearest one.
- removeUniqueIdSubscriber(ObjectRemovedEvent(folder))
+ removeUniqueIdSubscriber(folder, ObjectRemovedEvent(parent_folder))
self.assertRaises(KeyError, self.utility.getObject, id)
self.assertRaises(KeyError, self.utility1.getObject, id1)
self.assertEquals(len(events), 1)
- self.assertEquals(events[0].original_event.object, folder)
+ self.assertEquals(events[0].object, folder)
+ self.assertEquals(events[0].original_event.object, parent_folder)
def test_addUniqueIdSubscriber(self):
from zope.app.uniqueid import addUniqueIdSubscriber
from zope.app.container.contained import ObjectAddedEvent
from zope.app.uniqueid.interfaces import IUniqueIdAddedEvent
+ parent_folder = self.root['folder1']['folder1_1']
folder = self.root['folder1']['folder1_1']['folder1_1_1']
setSite(self.folder1_1)
@@ -258,14 +261,15 @@
# This should unregister the object in all utilities, not just the
# nearest one.
- addUniqueIdSubscriber(ObjectAddedEvent(folder))
+ addUniqueIdSubscriber(folder, ObjectAddedEvent(parent_folder))
# Check that the folder got registered
id = self.utility.getId(folder)
id1 = self.utility1.getId(folder)
self.assertEquals(len(events), 1)
- self.assertEquals(events[0].original_event.object, folder)
+ self.assertEquals(events[0].original_event.object, parent_folder)
+ self.assertEquals(events[0].object, folder)
def test_suite():
More information about the Zope3-Checkins
mailing list