[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/ComponentArchitecture - IServiceManagerContainer.py:1.1 NextService.py:1.1 ServiceManagerContainer.py:1.1 configure.zcml:1.6 hooks.py:1.4
Jim Fulton
jim@zope.com
Thu, 1 Aug 2002 14:42:40 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/App/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv5741/lib/python/Zope/App/ComponentArchitecture
Modified Files:
configure.zcml hooks.py
Added Files:
IServiceManagerContainer.py NextService.py
ServiceManagerContainer.py
Log Message:
Removed dependcies of:
Zope.ComponentArchitecture
Zope.Configuration
Zope.Exceptions
Zope.Testing
on other packages, especially App, in preparation for making these
packages part of Zope 2 and useful outside of the Zope application.
In particular, all placeful service support was moved to
Zope.App.ComponentArchitecture.
Placeful service implementors should get the nextService and
nextServiceManager functions from
Zope.App.ComponentArchitecture.NextService.
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/IServiceManagerContainer.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: IServiceManagerContainer.py,v 1.1 2002/08/01 18:42:09 jim Exp $
"""
from Interface import Interface
class IReadServiceManagerContainer(Interface):
def getServiceManager():
"""Returns the service manager contained in this object.
If there isn't a service manager, raise a component lookup.
"""
def queryServiceManager(default=None):
"""Returns the service manager contained in this object.
If there isn't a service manager, return the default.
"""
def hasServiceManager():
"""Query to find out if the component defines a service manager."""
class IWriteServiceManagerContainer(Interface):
def setServiceManager(sm):
"""Sets the service manager for this object."""
class IServiceManagerContainer(IReadServiceManagerContainer,
IWriteServiceManagerContainer):
pass
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/NextService.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Support for delegation among service managers
$Id: NextService.py,v 1.1 2002/08/01 18:42:09 jim Exp $
"""
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Zope.ComponentArchitecture.GlobalServiceManager import serviceManager
from Zope.Proxy.ContextWrapper import getWrapperContainer
from Zope.Proxy.ProxyIntrospection import removeAllProxies
from IServiceManagerContainer import IServiceManagerContainer
from hooks import getServiceManager_hook
# placeful service manager convenience tools
def queryNextServiceManager(context, default=None):
try:
return getNextServiceManager(context)
except ComponentLookupError:
return default
def getNextService(context, name):
service = queryNextService(context, name)
if service is None:
raise ComponentLookupError('service', name)
return service
def queryNextService(context, name, default=None):
try:
sm = getNextServiceManager(context)
except ComponentLookupError:
return default
return sm.queryService(name, default)
def getNextServiceManager(context):
"""if the context is a service manager or a placeful service, tries
to return the next highest service manager"""
# get this service manager
sm = getServiceManager_hook(context)
if sm is serviceManager:
raise ComponentLookupError('service manager')
# get the service manager container, which ought to be the context
# contaioner.
container = getWrapperContainer(sm)
# But we're *really* paranoid, so we'll double check.
while ((container is not None) and not
IServiceManagerContainer.isImplementedBy(
removeAllProxies(container))
):
container = getWrapperContainer(container) # we should be
# Now we need to step up so we can look for a service manager above.
context = getWrapperContainer(container)
# But we have to make sure we haven't got the same object..
while (context is not None) and (context == container):
context = getWrapperContainer(context)
return getServiceManager_hook(context)
=== Added File Zope3/lib/python/Zope/App/ComponentArchitecture/ServiceManagerContainer.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.
#
##############################################################################
"""
Revision information:
$Id: ServiceManagerContainer.py,v 1.1 2002/08/01 18:42:09 jim Exp $
"""
from IServiceManagerContainer import IServiceManagerContainer
from Zope.ComponentArchitecture.IServiceService import IServiceService
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
_marker = object()
class ServiceManagerContainer:
__implements__ = IServiceManagerContainer
############################################################
# Implementation methods for interface
# Zope.App.ComponentArchitecture.IServiceManagerContainer.
def hasServiceManager(self):
'''See interface IReadServiceManagerContainer'''
return hasattr(self, '_ServiceManagerContainer__sm')
def getServiceManager(self):
'''See interface IReadServiceManagerContainer'''
try:
return self.__sm
except AttributeError:
raise ComponentLookupError('no service manager defined')
def queryServiceManager(self, default=None):
'''See interface IReadServiceManagerContainer'''
return getattr(self, '_ServiceManagerContainer__sm', default)
def setServiceManager(self, sm):
'''See interface IWriteServiceManagerContainer'''
if IServiceService.isImplementedBy(sm):
self.__sm = sm
else:
raise ValueError('setServiceManager requires an IServiceService')
#
############################################################
=== Zope3/lib/python/Zope/App/ComponentArchitecture/configure.zcml 1.5 => 1.6 ===
component='.GlobalResourceService.resourceService' />
<hookable name=".getServiceManager" />
- <hookable name=".getNextServiceManager" />
<hook module="Zope.ComponentArchitecture"
name="getServiceManager"
implementation="
Zope.App.ComponentArchitecture.hooks.getServiceManager_hook" />
- <hook module="Zope.ComponentArchitecture"
- name="getNextServiceManager"
- implementation="
- Zope.App.ComponentArchitecture.hooks.getNextServiceManager_hook" />
</zopeConfigure>
=== Zope3/lib/python/Zope/App/ComponentArchitecture/hooks.py 1.3 => 1.4 ===
$Id$
"""
from Zope.ComponentArchitecture.IServiceService import IServiceService
-from Zope.ComponentArchitecture.IServiceManagerContainer \
+from Zope.App.ComponentArchitecture.IServiceManagerContainer \
import IServiceManagerContainer
from Zope.ComponentArchitecture.Exceptions import ComponentLookupError
from Zope.Proxy.ContextWrapper import getWrapperContainer, ContextWrapper
@@ -50,32 +50,3 @@
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"""
-
- # get this service manager
- sm = getServiceManager_hook(context)
- if sm is serviceManager:
- raise ComponentLookupError('service manager')
-
- # get the service manager container, which ought to be the context
- # contaioner.
- container = getWrapperContainer(sm)
-
- # But we're *really* paranoid, so we'll double check.
- while ((container is not None) and not
- IServiceManagerContainer.isImplementedBy(
- removeAllProxies(container))
- ):
- container = getWrapperContainer(container) # we should be
-
- # Now we need to step up so we can look for a service manager above.
- context = getWrapperContainer(container)
-
- # But we have to make sure we haven't got the same object..
- while (context is not None) and (context == container):
- context = getWrapperContainer(context)
-
- return getServiceManager_hook(context)