[Zope3-checkins] CVS: Zope3/src/zope/app/services - hub.py:1.16
Stephan Richter
srichter@cosmos.phy.tufts.edu
Tue, 8 Jul 2003 20:57:23 -0400
Update of /cvs-repository/Zope3/src/zope/app/services
In directory cvs.zope.org:/tmp/cvs-serv22743/src/zope/app/services
Modified Files:
hub.py
Log Message:
I subscribed the HubId service to listen to the IObjectDeletedEvent and
IObjectModifiedEvent. This was not done, so that the object hub was left
in a broken state after deleting an object and the indexes were out of
sync almost immediately.
I have no clue how to add a test for this, but I had a couple of errors
in the code before and it caught them in other tests. I guess we should
really add functional tests for this.
=== Zope3/src/zope/app/services/hub.py 1.15 => 1.16 ===
--- Zope3/src/zope/app/services/hub.py:1.15 Sat Jun 7 05:56:19 2003
+++ Zope3/src/zope/app/services/hub.py Tue Jul 8 20:57:19 2003
@@ -27,12 +27,14 @@
from zope.app.traversing import getPath, canonicalPath
-from zope.component import getAdapter
+from zope.component import getAdapter, getService
from zope.exceptions import NotFoundError
from zope.context import ContextMethod
from zope.proxy import removeAllProxies
+from zope.app.services.servicenames import EventSubscription
from zope.app.interfaces.traversing import ITraverser
+from zope.app.interfaces.container import IAddNotifiable, IDeleteNotifiable
from zope.app.interfaces.event import IObjectRemovedEvent, IObjectEvent
from zope.app.interfaces.event import IObjectMovedEvent, IObjectCreatedEvent
from zope.app.interfaces.event import IObjectModifiedEvent
@@ -172,7 +174,7 @@
# concerned, and if it doesn't know how to do something, it won't
# ask anything else to try. Everything else is YAGNI for now.
- implements(IObjectHub, ISimpleService)
+ implements(IObjectHub, ISimpleService, IAddNotifiable, IDeleteNotifiable)
def __init__(self):
ServiceSubscriberEventChannel.__init__(self)
@@ -181,6 +183,18 @@
self.__hubid_to_path = IOBTree()
# unicode pathslash --> int
self.__path_to_hubid = OIBTree()
+
+ def afterAddHook(self, hub, container):
+ '''See interface IAddNotifiable'''
+ events = getService(hub, EventSubscription)
+ events.subscribe(hub, IObjectModifiedEvent)
+ events.subscribe(hub, IObjectRemovedEvent)
+
+ def beforeDeleteHook(self, hub, container):
+ '''See interface IDeleteNotifiable'''
+ events = getService(hub, EventSubscription)
+ events.unsubscribe(hub, IObjectModifiedEvent)
+ events.unsubscribe(hub, IObjectRemovedEvent)
def notify(wrapped_self, event):
'''See interface ISubscriber'''