[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/index - subscribers.py:1.3

Guido van Rossum guido@python.org
Sun, 8 Dec 2002 15:36:29 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/index
In directory cvs.zope.org:/tmp/cvs-serv26467

Modified Files:
	subscribers.py 
Log Message:
Minor refactoring to look up the hub once per external call.


=== Zope3/lib/python/Zope/App/index/subscribers.py 1.2 => 1.3 ===
--- Zope3/lib/python/Zope/App/index/subscribers.py:1.2	Fri Dec  6 08:20:15 2002
+++ Zope3/lib/python/Zope/App/index/subscribers.py	Sun Dec  8 15:36:29 2002
@@ -61,7 +61,8 @@
 
     def notify(wrapped_self, event):
         """An event occured. Perhaps register this object with the hub."""
-        self._registerObject(event.object)
+        hub = getService(wrapped_self, "ObjectHub")
+        self._registerObject(event.object, hub)
     notify = ContextMethod(notify)
 
     currentlySubscribed = False # Default subscription state
@@ -87,11 +88,12 @@
 
     def registerExisting(wrapped_self):
         object = findContentObject(wrapped_self)
-        wrapped_self._registerTree(object)
+        hub = getService(wrapped_self, "ObjectHub")
+        wrapped_self._registerTree(object, hub)
     registerExisting = ContextMethod(registerExisting)
 
-    def _registerTree(wrapped_self, object):
-        wrapped_self._registerObject(object)
+    def _registerTree(wrapped_self, object, hub):
+        wrapped_self._registerObject(object, hub)
         # XXX Policy decision: only traverse into folders
         if not IFolder.isImplementedBy(object):
             return
@@ -101,18 +103,15 @@
             # XXX Once traverseName is refactored, should get an
             #     ITraversable from object and pass it to traverseName
             sub_object = traverseName(object, name)
-            wrapped_self._registerTree(sub_object)
+            wrapped_self._registerTree(sub_object, hub)
     _registerTree = ContextMethod(_registerTree)
 
-    def _registerObject(wrapped_self, object):
+    def _registerObject(wrapped_self, object, hub):
         # XXX Policy decision: register absolutely everything
         try:
-            getService(wrapped_self, "ObjectHub").register(object)
+            hub.register(object)
         except ObjectHubError:
-            # Probably already registered
-            # XXX It would be more convenient if register() returned
-            #     a bool indicating whether the object was already
-            #     registered, we wouldn't have to catch this exception.
+            # Already registered
             pass
     _registerObject = ContextMethod(_registerObject)