[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager - IServiceManager.py:1.1.2.5 ServiceManager.py:1.1.2.9 hooks.py:1.1.2.4 service-manager.zcml:1.1.2.4

Gary Poster garyposter@earthlink.net
Mon, 29 Apr 2002 19:20:35 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv1556/App/OFS/ServiceManager

Modified Files:
      Tag: Zope-3x-branch
	IServiceManager.py ServiceManager.py hooks.py 
	service-manager.zcml 
Log Message:
ComponentArchitecture reorganization; addition of for_container; addition of IWriteContainer.isAddable.

good news: all tests pass; bad news: after the new security system, my changes have some problems.  I had to punt on the default contents view of all folders for instance--hasServiceManager is causing a problem for some reason I couldn't divine, even with Shane's Checker tool.  I commented out the offending code on the contents.pt just to keep things up.

I tagged before committing: gary_CA-reorganization

changes more in depth (as I understand it, all or most approved :-) ):

(in ComponentArchitecture:)
 * changing implementation names to Global* (i.e., AdapterService becomes 
GlobalAdapterService) and giving each its own file (many are clumped together 
in hooks.py)
 * removing hooks.py in ComponentArchitecture, putting all functions in appropriate module above (i.e. getAdapter will be in the adapter module)
 * largely removing indirection (_hook) except for getService and 
getNextService
 * changing IServiceService.py to IServiceManager
 * changing Service.py to GlobalServiceManager.py (and class name too)
 * removing "provide*" functions (i.e., provideAdapter, provideUtility, etc.) 
and "defineService" from the __init__.py imports
 * change all global services to classes with appropriate methods as per 
interfaces
 * update all tests 
 * remove all of the "provide*" functions from the interfaces
 * renamed IComponentArchitecture to IPlacefulComponentArchitecture (hereafter IPCA), after long discussion with SteveA 
 * list Resources as one of core CA services in IPlacefulComponentArchitecture
 * build actual IPCA interface, not just import of service interfaces (because we want IPCA to be placeful, but the service interfaces do not need to be)
 * place functions implementing ICA actually in __init__
 * explicitly setting up services in zcml
 * created Global service interfaces, and placed the "provides" and "set" and "define" functions there: however, to keep the main interfaces clean and clear, I placed these global interfaces in the same file as the global implementations, hoping to clarify that these are not reusable interfaces but descriptive, one-time interfaces
 * built PlacefulSetup in Zope.ComponentArchitecture.tests for more specific CleanUp (a subclass).  PlacefulSetup is in the tests folder of the local ServiceManager.  AddableSetup also is available, in the AddableService tests.

(elsewhere in Zope3)
 * built for_container in addables
 * built isAddable for containers (after discussion with Jim, we decided an addable "contains" attribute in the zcml might not be the way to go.  I chose the isAddable approach for a number of reasons)
 * addableservice does some more checks in getting the addable list, pertinent to the above and to whether it can find the appropriate factories
 * a few more tests: a start of one in the local event service, and some more here and there

I'm sorry to add to the confusion of the big security changes, but I needed to either trash these changes or commit them: I'm a bit out of time for the moment.  If all else fails, again, I did tag the previous version.



=== Zope3/lib/python/Zope/App/OFS/ServiceManager/IServiceManager.py 1.1.2.4 => 1.1.2.5 ===
 """
 from Interface import Interface
-from Zope.ComponentArchitecture.IServiceService import IServiceService
+from Zope.ComponentArchitecture.IServiceManager import IServiceManager as \
+  IServiceService # fix once this package is changed to LocalServiceManager
 from Zope.App.OFS.Container.IContainer import IContainer
 
 class IServiceManager(IServiceService, IContainer):


=== Zope3/lib/python/Zope/App/OFS/ServiceManager/ServiceManager.py 1.1.2.8 => 1.1.2.9 ===
 from Zope.ComponentArchitecture import getService, \
      getNextServiceManager, getNextService
-from Zope.ComponentArchitecture.Service import UndefinedService
-from Zope.ComponentArchitecture.Service import InvalidService
+from Zope.ComponentArchitecture.GlobalServiceManager import UndefinedService
+from Zope.ComponentArchitecture.GlobalServiceManager import InvalidService
 from Zope.Exceptions import NotFoundError, ZopeError
 from Zope.App.OFS.Folder.Folder import Folder
 from Zope.ContextWrapper import ContextMethod
@@ -36,10 +36,10 @@
     def __init__(self):
         self.__bindings = {}
         super(ServiceManager, self).__init__()
-        
+
 
     def getServiceDefinitions(wrapped_self):
-        """ see IServiceService Interface """
+        """ see IServiceManager Interface """
         # Get the services defined here and above us, if any (as held
         # in a ServiceInterfaceService, presumably)
         sm=getNextServiceManager(wrapped_self)
@@ -49,26 +49,28 @@
         # since there is no way to define an interface TTW right now,
         # worrying about this further is pointless--it probably will be
         # an interface service evetually though...so this would be useful then:
-        
-        serviceInterfaceServ=wrapped_self.__bindings.get('ServiceInterfaceService')
+
+        serviceInterfaceServ= \
+             wrapped_self.__bindings.get('ServiceInterfaceService')
         if serviceInterfaceServ:
-            serviceDefs.update(dict(wrapped_self.getObject(serviceInterfaceServ).objectItems()))
+            serviceDefs.update(dict(
+               wrapped_self.getObject(serviceInterfaceServ).objectItems()))
         return serviceDefs
-    
+
     getServiceDefinitions=ContextMethod(getServiceDefinitions)
-    
+
     def getService(wrapped_self, name):
-        """ see IServiceService Interface"""
-        
+        """ see IServiceManager Interface"""
+
         service = wrapped_self.__bindings.get(name)
-                
+
         if service:
             return ContextWrapper(wrapped_self.getObject(service),
                                   wrapped_self, name=name)
             # XXX we don't need to check security, do we?
-            
+
         return getNextService(wrapped_self, name)
-    
+
     getService=ContextMethod(getService)
 
     def getBoundService(self, name):
@@ -77,7 +79,7 @@
         return self.__bindings.get(name)
 
     def bindService(self, serviceName, serviceComponentName):
-        """ see IServiceManager Interface"""        
+        """ see IServiceManager Interface"""
 
         # This could raise a KeyError if we don't have this component
         serviceComponent = self.getObject(serviceComponentName)
@@ -92,20 +94,21 @@
 
         # Services are added to the Manager through the Folder interface
         # self.setObject(name, component)
-        
+
         # trigger persistence
         self.__bindings = self.__bindings
-        
+
         self.__bindings[serviceName] = serviceComponentName
-    
-    bindService=ContextMethod(bindService) # needed because of call to getServiceDefinitions
+
+    bindService=ContextMethod(bindService) # needed because of call to
+    # getServiceDefinitions
 
     def unbindService(self, serviceName):
         """ see IServiceManager Interface """
-        
+
         # trigger persistence
         self.__bindings = self.__bindings
-        
+
         del self.__bindings[serviceName]
 
 


=== Zope3/lib/python/Zope/App/OFS/ServiceManager/hooks.py 1.1.2.3 => 1.1.2.4 ===
 $Id$
 """
-from Zope.ComponentArchitecture.IServiceService import IServiceService
+from Zope.ComponentArchitecture.IServiceManager import IServiceManager
 from Zope.ComponentArchitecture.IServiceManagerContainer import IServiceManagerContainer
-from Zope.Proxy.ContextWrapper import getWrapperContainer
-from Zope.ComponentArchitecture import getGlobalServiceManager, \
-     getServiceManager
+from Zope.Proxy.ContextWrapper import getWrapperContainer, ContextWrapper
+from Zope.ComponentArchitecture import getServiceManager
 from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
-from Zope.ComponentArchitecture.Service import serviceManager
+from Zope.ComponentArchitecture.GlobalServiceManager import serviceManager
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
     
 def getServiceManager_hook(context):
@@ -31,7 +30,7 @@
     """
     while context is not None:
         # if the context is actually a service or service manager...
-        if IServiceService.isImplementedBy(removeAllProxies(context)):
+        if IServiceManager.isImplementedBy(removeAllProxies(context)):
             return context
         if IServiceManagerContainer.isImplementedBy(
             removeAllProxies(context)):
@@ -40,7 +39,7 @@
             except ComponentLookupError:
                 pass
         context = getWrapperContainer(context)
-    return getGlobalServiceManager()
+    return serviceManager
 
 def getNextServiceManager_hook(context):
     """if the context is a service manager or a placeful service, tries
@@ -48,7 +47,10 @@
     context=getServiceManager(context)
     if context is serviceManager: return None
     context=getWrapperContainer(context)
-    while context and not IServiceManagerContainer.isImplementedBy(context):
+    while context and not \
+          IServiceManagerContainer.isImplementedBy(
+              removeAllProxies(context)
+              ):
         context=getWrapperContainer(context) # we should be
     # able to rely on the first step getting us a
     # ServiceManagerContainer


=== Zope3/lib/python/Zope/App/OFS/ServiceManager/service-manager.zcml 1.1.2.3 => 1.1.2.4 ===
 <include package="Zope.App.OFS.ServiceManager.Views" file="views.zcml" />
 
-<hook module="Zope.ComponentArchitecture.hooks" name="getServiceManager"
+<hook module="Zope.ComponentArchitecture" name="getServiceManager"
    implementation=".hooks.getServiceManager_hook" />
-<hook module="Zope.ComponentArchitecture.hooks"
+<hook module="Zope.ComponentArchitecture"
     name="getNextServiceManager"
     implementation=".hooks.getNextServiceManager_hook" />