[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - hooks.py:1.1 configure.zcml:1.4
Jim Fulton
jim@zope.com
Tue, 2 Jul 2002 19:44:43 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv17483/lib/python/Zope/App/ComponentArchitecture
Modified Files:
configure.zcml
Added Files:
hooks.py
Log Message:
Refactored service manager and service lookup get routines to be
consistent with the Zope 3 get style, using get and query
routines. Added some missing tests.
Moved the service-manager lookup hooks to
Zope.App.ComponentArchitecture.
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/hooks.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""
$Id: hooks.py,v 1.1 2002/07/02 23:44:12 jim Exp $
"""
from Zope.ComponentArchitecture.IServiceManager import IServiceManager
from Zope.ComponentArchitecture.IServiceManagerContainer \
import IServiceManagerContainer
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Zope.Proxy.ContextWrapper import getWrapperContainer, ContextWrapper
from Zope.ComponentArchitecture import getServiceManager
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Zope.ComponentArchitecture.GlobalServiceManager import serviceManager
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from Zope.Security.Proxy import trustedRemoveSecurityProxy
def getServiceManager_hook(context):
"""
context based lookup, with fallback to component architecture
service manager if no service manager found within context
"""
while context is not None:
clean_context = removeAllProxies(context)
# if the context is actually a service or service manager...
if IServiceManager.isImplementedBy(clean_context):
return trustedRemoveSecurityProxy(context)
if (IServiceManagerContainer.isImplementedBy(clean_context) and
clean_context.hasServiceManager()
):
return ContextWrapper(
trustedRemoveSecurityProxy(context.getServiceManager()),
context,
name="++etc++Services",
)
context = getWrapperContainer(context)
return serviceManager
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_hook(context)
if context is serviceManager:
raise ComponentLookupError('service manager')
context=getWrapperContainer(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
context=getWrapperContainer(context)
return getServiceManager_hook(context)
=== Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml 1.3 => 1.4 ===
<hookable name=".getNextServiceManager" />
+ <hook module="Zope.ComponentArchitecture"
+ name="getServiceManager"
+ implementation=".hooks.getServiceManager_hook" />
+ <hook module="Zope.ComponentArchitecture"
+ name="getNextServiceManager"
+ implementation=".hooks.getNextServiceManager_hook" />
+
</zopeConfigure>