[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/OFS/ServiceManager - ServiceManager.py:1.1.2.6 hooks.py:1.1.2.2 service-manager.zcml:1.1.2.3
Gary Poster
garyposter@earthlink.net
Wed, 17 Apr 2002 15:13:06 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/ServiceManager
In directory cvs.zope.org:/tmp/cvs-serv31331/App/OFS/ServiceManager
Modified Files:
Tag: Zope-3x-branch
ServiceManager.py hooks.py service-manager.zcml
Log Message:
This commit makes the following changes:
The hookable zcml mechanism now requires an intermediary method to overwrite: see the hookables in Zope.ComponentArchitecture for an example
IServiceService, Service, and ServiceManager now all have this signature for the getService method: name. They did use context, name. The context, name signature is still used for the main ComponentArchitecture getService function.
the getServiceDefinition function now requires context
A ServiceContainer returns a wrapped ServiceManager; a ServiceManager returns a wrapped Service.
ServiceManager now overrides two ComponentArchitecture hooks: getServiceManager and getNextServiceManager
getNextServiceManager and getNextService are two new ComponentArchitecture functions useful for placeful services
The Zope.Publisher.Browser.BrowserRequest now includes the Zope2 class definition of record: this means that the placeful RoleService is inching forward towards working.
tests have been updated to reflect these changes.
=== Zope3/lib/python/Zope/App/OFS/ServiceManager/ServiceManager.py 1.1.2.5 => 1.1.2.6 ===
from Zope.ComponentArchitecture.IServiceManagerContainer \
import IServiceManagerContainer
-from Zope.ComponentArchitecture import getService, getServiceDefinitions
+from Zope.ComponentArchitecture import getService, \
+ getNextServiceManager, getNextService
from Zope.ComponentArchitecture.Service import UndefinedService
from Zope.ComponentArchitecture.Service import InvalidService
from Zope.Exceptions import NotFoundError, ZopeError
from Zope.App.OFS.Folder.Folder import Folder
-from Zope.ContextWrapper import getinnercontext
+from Zope.ContextWrapper import getinnercontext, Wrapper
from Zope.App.OFS.Container.BTreeContainer import BTreeContainer
class ServiceManager(BTreeContainer):
@@ -38,46 +39,31 @@
def getServiceDefinitions(self):
""" see IServiceService Interface """
- # Get the services defined above us
- #serviceDefs = []
- #parentSM = self._findParentServiceManager()
- #if parentSM is not None:
- # serviceDefs += parentSM.getServiceDefinitions()
- #else:
- # serviceDefs += getServiceDefinitions()
- #
- #return serviceDefs
- return getServiceDefinitions()
-
- def _findParentServiceManager(self):
- parent = getinnercontext(self)
-
- if IServiceManagerContainer.isImplementedBy(parent):
- sm = parent.getServiceManager()
- return sm
+ # Get the services defined here and above us, if any (as held
+ # in a ServiceInterfaceService, presumably)
+ sm=getNextServiceManager(self)
+ if sm is not None:
+ serviceDefs=sm.getServiceDefinitions()
+ else: serviceDefs={}
+ # 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=self.__bindings.get('ServiceInterfaceService')
+ if serviceInterfaceServ:
+ serviceDefs.update(dict(self.getObject(serviceInterfaceServ).objectItems()))
+ return serviceDefs
- def getService(self, object, name):
+ def getService(self, name):
""" see IServiceService Interface"""
service = self.__bindings.get(name)
if service:
- return self.getObject(service)
-
- object = self._findParentServiceManager()
- while object is not None:
- # object = getinnercontext(object)
- #
- # if IServiceManagerContainer.isImplementedBy(object):
- # sm = object.getServiceManager()
- # if sm:
- # return sm.getService(object, name)
- return sm.getService(object, name)
-
- # fallback to the ComponentArchitecture Service Manager
- # XXX when this called the original object might no longer be
- # the context
- return getService(object, name)
+ return Wrapper(self.getObject(service), self, name=name)
+ # we don't need to check security, do we?
+
+ return getNextService(self, name)
def getBoundService(self, name):
""" see IServiceManager Interface"""
=== Zope3/lib/python/Zope/App/OFS/ServiceManager/hooks.py 1.1.2.1 => 1.1.2.2 ===
from Zope.ComponentArchitecture.IServiceManagerContainer import IServiceManagerContainer
from Zope.ContextWrapper import getinnercontext
-from Zope.ComponentArchitecture import getGlobalServiceManager
-
-def _getService(context, name):
- """
- context based lookup
- """
- return _getServiceManager(context).getService(context, name)
-
-def _getServiceManager(context):
+from Zope.ComponentArchitecture import getGlobalServiceManager, \
+ getServiceManager
+from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
+from Zope.ComponentArchitecture.Service import serviceManager
+
+def getServiceManager_hook(context):
"""
context based lookup, with fallback to component architecture
service manager if no service manager found within context
@@ -35,15 +32,22 @@
# if the context is actually a service or service manager...
if IServiceService.isImplementedBy(context): return context
if IServiceManagerContainer.isImplementedBy(context):
- sm = context.getServiceManager()
- if sm is not None:
- return sm
+ try:
+ return context.getServiceManager()
+ except ComponentLookupError:
+ pass
context = getinnercontext(context)
return getGlobalServiceManager()
-
-def _getServiceDefinitions(context): # needed? not hooked in now
- """
- context based lookup to get service defintions
- """
- return _getServiceManager(context).getServiceDefinitions()
\ No newline at end of file
+def getNextServiceManager_hook(context):
+ """if the context is a service manager or a placeful service, tries
+ to return the next highest service manager"""
+ context=getServiceManager(context)
+ if context is serviceManager: return None
+ context=getinnercontext(context)
+ while context and not IServiceManagerContainer.isImplementedBy(context):
+ context=getinnercontext(context) # we should be
+ # able to rely on the first step getting us a
+ # ServiceManagerContainer
+ context=getinnercontext(context)
+ return getServiceManager(context)
\ No newline at end of file
=== Zope3/lib/python/Zope/App/OFS/ServiceManager/service-manager.zcml 1.1.2.2 => 1.1.2.3 ===
<include package="Zope.App.OFS.ServiceManager.Views" file="views.zcml" />
-<hook module="Zope.ComponentArchitecture" name="getServiceManager"
- implementation=".hooks._getServiceManager" />
-
-<hook module="Zope.ComponentArchitecture" name="getService"
- implementation=".hooks._getService" />
-
-<!--hook module="Zope.ComponentArchitecture" name="getServiceDefinitions"
- implementation=".hooks._getServiceDefinitions" /-->
+<hook module="Zope.ComponentArchitecture.hooks" name="getServiceManager"
+ implementation=".hooks.getServiceManager_hook" />
+<hook module="Zope.ComponentArchitecture.hooks"
+ name="getNextServiceManager"
+ implementation=".hooks.getNextServiceManager_hook" />
</zopeConfigure>