[Zope3-checkins] CVS: Zope3/src/zope/app/component - hooks.py:1.3 nextservice.py:1.3

Jim Fulton jim@zope.com
Tue, 11 Mar 2003 16:09:11 -0500


Update of /cvs-repository/Zope3/src/zope/app/component
In directory cvs.zope.org:/tmp/cvs-serv1075/src/zope/app/component

Modified Files:
	hooks.py nextservice.py 
Log Message:
Added a check to getNextServiceManager to raise an error if you call
it with a context that isn't "in" an IContainment root.  This check is
to make it easier to spot bugs, especially in tests, that occur when 
you don't create the right context and end up getting a global service
when you expect a local one. 


=== Zope3/src/zope/app/component/hooks.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/component/hooks.py:1.2	Wed Dec 25 09:12:45 2002
+++ Zope3/src/zope/app/component/hooks.py	Tue Mar 11 16:08:40 2003
@@ -25,8 +25,9 @@
 from zope.component.service import serviceManager
 from zope.proxy.introspection import removeAllProxies
 from zope.security.proxy import trustedRemoveSecurityProxy
+from zope.app.traversing import IContainmentRoot
 
-def getServiceManager_hook(context):
+def getServiceManager_hook(context, local=False):
     """
     context based lookup, with fallback to component architecture
     service manager if no service manager found within context
@@ -47,6 +48,16 @@
                 name="++etc++Services",
                 )
 
-        context = getWrapperContainer(context)
+        container = getWrapperContainer(context)
+        if container is None:
+            if local:
+                # Check to make sure that when we run out of context, we
+                # have a root object:
+                if not IContainmentRoot.isImplementedBy(context):
+                    raise TypeError("Not enough context to get next "
+                                    "service manager")
+                break
+            
+        context = container
 
     return serviceManager


=== Zope3/src/zope/app/component/nextservice.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/component/nextservice.py:1.2	Wed Dec 25 09:12:45 2002
+++ Zope3/src/zope/app/component/nextservice.py	Tue Mar 11 16:08:40 2003
@@ -55,7 +55,7 @@
     # get this service manager
     sm = getServiceManager_hook(context)
     if sm is serviceManager:
-        raise ComponentLookupError('service manager')
+        raise ComponentLookupError('Services')
 
     # get the service manager container, which ought to be the context
     # contaioner.
@@ -75,4 +75,4 @@
     while (context is not None) and (context == container):
         context = getWrapperContainer(context)
 
-    return getServiceManager_hook(context)
+    return getServiceManager_hook(context, local=True)