[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/component/ Changed the subscriber that sets sites to subscribe to ISite as well

Jim Fulton jim at zope.com
Fri Jun 10 12:03:40 EDT 2005


Log message for revision 30737:
  Changed the subscriber that sets sites to subscribe to ISite as well
  as the event so that it is *only* called when traversing sites.
  

Changed:
  U   Zope3/trunk/src/zope/app/component/configure.zcml
  U   Zope3/trunk/src/zope/app/component/site.py
  U   Zope3/trunk/src/zope/app/component/site.txt
  U   Zope3/trunk/src/zope/app/component/tests/test_site.py

-=-
Modified: Zope3/trunk/src/zope/app/component/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/component/configure.zcml	2005-06-10 14:16:34 UTC (rev 30736)
+++ Zope3/trunk/src/zope/app/component/configure.zcml	2005-06-10 16:03:39 UTC (rev 30737)
@@ -136,7 +136,8 @@
       />
 
   <subscriber
-      for="zope.app.publication.interfaces.IBeforeTraverseEvent"
+      for=".interfaces.ISite
+           zope.app.publication.interfaces.IBeforeTraverseEvent"
       handler=".site.threadSiteSubscriber"
       />
 

Modified: Zope3/trunk/src/zope/app/component/site.py
===================================================================
--- Zope3/trunk/src/zope/app/component/site.py	2005-06-10 14:16:34 UTC (rev 30736)
+++ Zope3/trunk/src/zope/app/component/site.py	2005-06-10 16:03:39 UTC (rev 30737)
@@ -275,13 +275,12 @@
         return zapi.getSiteManager(self)
 
 
-def threadSiteSubscriber(event):
+def threadSiteSubscriber(ob, event):
     """A subscriber to BeforeTraverseEvent
 
     Sets the 'site' thread global if the object traversed is a site.
     """
-    if interfaces.ISite.providedBy(event.object):
-        setSite(event.object)
+    setSite(ob)
 
 
 def clearThreadSiteSubscriber(event):
@@ -313,24 +312,6 @@
             # site manager
             return zapi.getGlobalSiteManager()
 
-
-def threadSiteSubscriber(event):
-    """A subscriber to BeforeTraverseEvent
-
-    Sets the 'site' thread global if the object traversed is a site.
-    """
-    if interfaces.ISite.providedBy(event.object):
-        setSite(event.object)
-
-
-def clearThreadSiteSubscriber(event):
-    """A subscriber to EndRequestEvent
-
-    Cleans up the site thread global after the request is processed.
-    """
-    clearSite()
-
-
 def changeSiteConfigurationAfterMove(site, event):
     """After a site is moved, its site manager links have to be updated."""
     next = None

Modified: Zope3/trunk/src/zope/app/component/site.txt
===================================================================
--- Zope3/trunk/src/zope/app/component/site.txt	2005-06-10 14:16:34 UTC (rev 30736)
+++ Zope3/trunk/src/zope/app/component/site.txt	2005-06-10 16:03:39 UTC (rev 30737)
@@ -92,7 +92,7 @@
   >>> from zope.app import publication
   >>> request = object()
   >>> ev = publication.interfaces.BeforeTraverseEvent(myfolder, request)
-  >>> site.threadSiteSubscriber(ev)
+  >>> site.threadSiteSubscriber(myfolder, ev)
 
 the nearest site is also recorded in a thread-global variable:
 

Modified: Zope3/trunk/src/zope/app/component/tests/test_site.py
===================================================================
--- Zope3/trunk/src/zope/app/component/tests/test_site.py	2005-06-10 14:16:34 UTC (rev 30736)
+++ Zope3/trunk/src/zope/app/component/tests/test_site.py	2005-06-10 16:03:39 UTC (rev 30737)
@@ -87,20 +87,12 @@
       >>> hooks.getSite() is None
       True
 
-    If a non-site is traversed, 
 
-      >>> ob = object()
       >>> request = object()
 
       >>> from zope.app import publication
-      >>> ev = publication.interfaces.BeforeTraverseEvent(ob, request)
       >>> from zope.app.component import site
-      >>> site.threadSiteSubscriber(ev)
 
-    still no site is set:
-
-      >>> hooks.getSite() is None
-      True
       
     On the other hand, if a site is traversed, 
 
@@ -109,7 +101,7 @@
       >>> mysite.setSiteManager(sm)
 
       >>> ev = publication.interfaces.BeforeTraverseEvent(mysite, request)
-      >>> site.threadSiteSubscriber(ev)
+      >>> site.threadSiteSubscriber(mysite, ev)
 
       >>> hooks.getSite()
       <CustomFolder mysite>



More information about the Zope3-Checkins mailing list