[Zope3-checkins]
SVN: Zope3/branches/srichter-blow-services/src/zope/app/
Milestone commit. Moved all stuff into bbb.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Dec 21 18:28:29 EST 2004
Log message for revision 28678:
Milestone commit. Moved all stuff into bbb.
Changed:
D Zope3/branches/srichter-blow-services/src/zope/app/adapter/
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/adapter/
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/
D Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/service.py
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/service.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/tests/
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/tests/
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/
D Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/tests.py
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/tests.py
D Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/utility.py
A Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/utility.py
D Zope3/branches/srichter-blow-services/src/zope/app/site/
D Zope3/branches/srichter-blow-services/src/zope/app/utility/
-=-
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/adapter (from rev 28644, Zope3/branches/srichter-blow-services/src/zope/app/adapter)
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site (from rev 28644, Zope3/branches/srichter-blow-services/src/zope/app/site)
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/service.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/site/service.py 2004-12-17 21:36:22 UTC (rev 28644)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/service.py 2004-12-21 23:28:27 UTC (rev 28678)
@@ -1,323 +0,0 @@
-##############################################################################
-#
-# 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.1 (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.
-#
-##############################################################################
-"""Service manager implementation
-
-A service manager has a number of roles:
-
- - A service service
-
- - A place to do TTW development or to manage database-based code
-
- - A registry for persistent modules. The Zope import hook uses the
- ServiceManager to search for modules. (This functionality will
- eventually be replaced by a separate module service.)
-
-$Id$
-"""
-import sys
-from transaction import get_transaction
-from zodbcode.module import PersistentModuleRegistry
-
-import zope.event
-import zope.interface
-from zope.component.exceptions import ComponentLookupError
-
-import zope.app.registration.interfaces
-from zope.app import zapi
-from zope.app.component.localservice import getNextService
-from zope.app.component.localservice import getNextServices
-from zope.app.container.btree import BTreeContainer
-from zope.app.container.constraints import ItemTypePrecondition
-from zope.app.container.contained import Contained
-from zope.app.container.interfaces import IContainer
-from zope.app.event import objectevent
-from zope.app.registration.interfaces import IRegistry
-from zope.app.traversing.interfaces import IContainmentRoot
-from zope.app.traversing.api import getPath
-from zope.app.location import inside
-from zope.app.site.folder import SiteManagementFolder
-from zope.app.registration.registration import ComponentRegistration
-from zope.app.registration.registration import RegistrationStack
-
-from zope.app.site.interfaces import IBindingAware, ILocalService
-from zope.app.site.interfaces import IPossibleSite, ISite, ISiteManager
-from zope.app.site.interfaces import IServiceRegistration
-
-class IRegisterableContainerContainer(zope.interface.Interface):
-
- def __setitem__(name, folder):
- """Add a site-management folder
- """
- __setitem__.precondition = ItemTypePrecondition(
- zope.app.registration.interfaces.IRegisterableContainer)
-
-
-class SiteManager(
- BTreeContainer,
- PersistentModuleRegistry,
- ):
-
- zope.interface.implements(
- ISiteManager,
- IRegisterableContainerContainer,
- IRegistry,
- )
-
- def __init__(self, site):
- self._bindings = {}
- self.__parent__ = site
- self.__name__ = '++etc++site'
- BTreeContainer.__init__(self)
- PersistentModuleRegistry.__init__(self)
- self.subSites = ()
- self._setNext(site)
- folder = SiteManagementFolder()
- zope.event.notify(objectevent.ObjectCreatedEvent(folder))
- self['default'] = folder
-
- def _setNext(self, site):
- """Find set the next service manager
- """
- while True:
- if IContainmentRoot.providedBy(site):
- # we're the root site, use the global sm
- self.next = zapi.getGlobalServices()
- return
- site = site.__parent__
- if site is None:
- raise TypeError("Not enough context information")
- if ISite.providedBy(site):
- self.next = site.getSiteManager()
- self.next.addSubsite(self)
- return
-
- def addSubsite(self, sub):
- """See ISiteManager interface
- """
- subsite = sub.__parent__
-
- # Update any sites that are now in the subsite:
- subsites = []
- for s in self.subSites:
- if inside(s, subsite):
- s.next = sub
- sub.addSubsite(s)
- else:
- subsites.append(s)
-
- subsites.append(sub)
- self.subSites = tuple(subsites)
-
- def queryRegistrationsFor(self, cfg, default=None):
- """See IRegistry"""
- return self.queryRegistrations(cfg.name, default)
-
- def queryRegistrations(self, name, default=None):
- """See INameRegistry"""
- return self._bindings.get(name, default)
-
- def createRegistrationsFor(self, cfg):
- """See IRegistry"""
- return self.createRegistrations(cfg.name)
-
- def createRegistrations(self, name):
- try:
- registry = self._bindings[name]
- except KeyError:
- registry = RegistrationStack(self)
- self._bindings[name] = registry
- self._p_changed = 1
- return registry
-
- def listRegistrationNames(self):
- return filter(self._bindings.get,
- self._bindings.keys())
-
- def queryActiveComponent(self, name, default=None):
- registry = self.queryRegistrations(name)
- if registry:
- registration = registry.active()
- if registration is not None:
- return registration.component
- return default
-
- def getServiceDefinitions(self):
- """See IServiceService
- """
- # Get the services defined here and above us, if any (as held
- # in a ServiceInterfaceService, presumably)
- sm = self.next
- if sm is not None:
- serviceDefs = sm.getServiceDefinitions()
- else:
- serviceDefs = {}
-
- return serviceDefs
-
- def getService(self, name):
- """See IServiceService
- """
-
- # This is rather tricky. Normally, getting a service requires
- # the use of other services, like the adapter service. We
- # need to be careful not to get into an infinate recursion by
- # getting out getService to be called while looking up
- # services, so we'll use _v_calling to prevent recursive
- # getService calls.
-
- if name == 'Services':
- return self # We are the service service
-
- if not getattr(self, '_v_calling', 0):
-
- self._v_calling = 1
- try:
- service = self.queryActiveComponent(name)
- if service is not None:
- return service
-
- finally:
- self._v_calling = 0
-
- return getNextService(self, name)
-
- def queryLocalService(self, name, default=None):
- """See ISiteManager
- """
-
- # This is rather tricky. Normally, getting a service requires
- # the use of other services, like the adapter service. We
- # need to be careful not to get into an infinate recursion by
- # getting our getService to be called while looking up
- # services, so we'll use _v_calling to prevent recursive
- # getService calls.
-
- if name == 'Services':
- return self # We are the service service
-
- if not getattr(self, '_v_calling', 0):
-
- self._v_calling = 1
- try:
- service = self.queryActiveComponent(name)
- if service is not None:
- return service
-
- finally:
- self._v_calling = 0
-
- return default
-
- def getInterfaceFor(self, service_type):
- """See IServiceService
- """
- for type, interface in self.getServiceDefinitions():
- if type == service_type:
- return interface
-
- raise NameError(service_type)
-
- def queryComponent(self, type=None, filter=None, all=0):
- local = []
- path = getPath(self)
- for pkg_name in self:
- package = self[pkg_name]
- for name in package:
- component = package[name]
- if type is not None and not type.providedBy(component):
- continue
- if filter is not None and not filter(component):
- continue
- local.append({'path': "%s/%s/%s" % (path, pkg_name, name),
- 'component': component,
- })
-
- if all:
- next_service_manager = self.next
- if IComponentManager.providedBy(next_service_manager):
- next_service_manager.queryComponent(type, filter, all)
-
- local += list(all)
-
- return local
-
- def findModule(self, name):
- # override to pass call up to next service manager
- mod = super(ServiceManager, self).findModule(name)
- if mod is not None:
- return mod
-
- sm = self.next
- try:
- findModule = sm.findModule
- except AttributeError:
- # The only service manager that doesn't implement this
- # interface is the global service manager. There is no
- # direct way to ask if sm is the global service manager.
- return None
- return findModule(name)
-
- def __import(self, module_name):
- mod = self.findModule(module_name)
- if mod is None:
- mod = sys.modules.get(module_name)
- if mod is None:
- raise ImportError(module_name)
-
- return mod
-
-ServiceManager = SiteManager # Backward compat
-
-class ServiceRegistration(ComponentRegistration):
- """Registrations for named components.
-
- This configures components that live in folders, by name.
- """
-
- serviceType = zapi.servicenames.Services
-
- zope.interface.implements(IServiceRegistration)
-
- def __init__(self, name, service, context=None):
- super(ServiceRegistration, self).__init__(service, None)
- self.name = name
-
- if context is not None:
- # Check that the object implements stuff we need
- self.__parent__ = context
- if not ILocalService.providedBy(service):
- raise TypeError(
- "service %r doesn't implement ILocalService" %
- service)
- # Else, this must be a hopeful test invocation
-
- def getInterface(self):
- service_manager = zapi.getServices(self)
- return service_manager.getInterfaceFor(self.name)
-
- def usageSummary(self):
- return self.name + " Service"
-
-
-def handleActivated(event):
- if isinstance(event.object, ServiceRegistration):
- service = event.object.component
- if IBindingAware.providedBy(service):
- service.bound(event.object.name)
-
-def handleDeactivated(event):
- if isinstance(event.object, ServiceRegistration):
- service = event.object.component
- if IBindingAware.providedBy(service):
- service.unbound(event.object.name)
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/service.py (from rev 28677, Zope3/branches/srichter-blow-services/src/zope/app/site/service.py)
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/site/tests (from rev 28677, Zope3/branches/srichter-blow-services/src/zope/app/site/tests)
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility (from rev 28644, Zope3/branches/srichter-blow-services/src/zope/app/utility)
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/tests.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/utility/tests.py 2004-12-17 21:36:22 UTC (rev 28644)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/tests.py 2004-12-21 23:28:27 UTC (rev 28678)
@@ -1,269 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-"""Utility service tests
-
-$Id$
-"""
-import unittest
-from StringIO import StringIO
-from persistent.interfaces import IPersistent
-
-from zope.component import getService
-from zope.component.exceptions import ComponentLookupError
-from zope.configuration.xmlconfig import xmlconfig, XMLConfig
-from zope.interface import Interface, implements
-from zope.testing.doctestunit import DocTestSuite
-
-import zope.app.security
-import zope.app.utility
-from zope.app.tests import setup
-from zope.app import utility, zapi
-from zope.app.annotation.interfaces import IAttributeAnnotatable
-from zope.app.dependable.interfaces import IDependable
-from zope.app.location.interfaces import ILocation
-from zope.app.traversing.api import traverse
-from zope.app.registration.interfaces import IRegistrationStack
-from zope.app.registration.interfaces import UnregisteredStatus
-from zope.app.registration.interfaces import RegisteredStatus
-from zope.app.registration.interfaces import ActiveStatus
-from zope.app.registration.interfaces import IRegistered
-from zope.app.site.tests import placefulsetup
-from zope.app.tests import setup
-from zope.app.tests.placelesssetup import PlacelessSetup
-from zope.app.utility.interfaces import ILocalUtility
-
-
-def configfile(s):
- return StringIO("""<configure
- xmlns='http://namespaces.zope.org/zope'
- i18n_domain='zope'>
- %s
- </configure>
- """ % s)
-
-class IFo(Interface): pass
-
-class IFoo(IFo):
- def foo(self): pass
-
-class IBar(Interface): pass
-
-
-class Foo(object):
- # We implement IRegistered and IDependable directly to
- # depend as little as possible on other infrastructure.
- __name__ = __parent__ = None
- implements(IFoo, ILocalUtility, IRegistered, IDependable)
-
- def __init__(self, name):
- self.name = name
- self._usages = []
- self._dependents = []
-
- def foo(self):
- return 'foo ' + self.name
-
- def addUsage(self, location):
- "See zope.app.registration.interfaces.IRegistered"
- if location not in self._usages:
- self._usages.append(location)
-
- def removeUsage(self, location):
- "See zope.app.registration.interfaces.IRegistered"
- self._usages.remove(location)
-
- def usages(self):
- "See zope.app.registration.interfaces.IRegistered"
- return self._usages
-
- def addDependent(self, location):
- "See zope.app.dependable.interfaces.IDependable"
- if location not in self._dependents:
- self._dependents.append(location)
-
- def removeDependent(self, location):
- "See zope.app.dependable.interfaces.IDependable"
- self._dependents.remove(location)
-
- def dependents(self):
- "See zope.app.dependable.interfaces.IDependable"
- return self._dependents
-
-
-class UtilityStub(object):
- implements(ILocation, IPersistent)
-
-
-class TestUtilityService(placefulsetup.PlacefulSetup, unittest.TestCase):
-
- def setUp(self):
- sm = placefulsetup.PlacefulSetup.setUp(self, site=True)
- setup.addService(sm, zapi.servicenames.Utilities,
- utility.LocalUtilityService())
-
- def test_queryUtility_delegates_to_global(self):
- utilityService = zapi.getGlobalService(zapi.servicenames.Utilities)
- utilityService.provideUtility(IFoo, Foo("global"))
- utilityService.provideUtility(IFoo, Foo("global bob"),
- name="bob")
-
- utility_service = getService("Utilities", self.rootFolder)
-
- # We changed the root (base) service. This doesn't normally
- # occur. We have to notify the local service that the base
- # has changes:
- utility_service.baseChanged()
-
- self.assert_(utility_service != utilityService)
-
- self.assertEqual(utility_service.queryUtility(IFoo).foo(),
- "foo global")
- self.assertEqual(utility_service.queryUtility(IFoo, "bob").foo(),
- "foo global bob")
- self.assertEqual(utility_service.queryUtility(IFo).foo(),
- "foo global")
- self.assertEqual(utility_service.queryUtility(IFo, "bob").foo(),
- "foo global bob")
-
- self.assertEqual(utility_service.queryUtility(IBar), None)
- self.assertEqual(utility_service.queryUtility(IBar, "bob"), None)
- self.assertEqual(utility_service.queryUtility(IFoo, "rob"), None)
-
- def test_getUtility_delegates_to_global(self):
- utilityService = zapi.getGlobalService(zapi.servicenames.Utilities)
- utilityService.provideUtility(IFoo, Foo("global"))
- utilityService.provideUtility(IFoo, Foo("global bob"),
- name="bob")
-
- utility_service = getService("Utilities", self.rootFolder)
- self.assert_(utility_service != utilityService)
-
- self.assertEqual(utility_service.getUtility(IFoo).foo(),
- "foo global")
- self.assertEqual(utility_service.getUtility(IFoo, "bob").foo(),
- "foo global bob")
- self.assertEqual(utility_service.getUtility(IFo).foo(),
- "foo global")
- self.assertEqual(utility_service.getUtility(IFo, "bob").foo(),
- "foo global bob")
-
-
- self.assertRaises(ComponentLookupError,
- utility_service.getUtility, IBar)
- self.assertRaises(ComponentLookupError,
- utility_service.getUtility, IBar, 'bob')
- self.assertRaises(ComponentLookupError,
- utility_service.getUtility, IFoo, 'rob')
-
-
- def test_registrationsFor_methods(self):
- utilities = getService("Utilities", self.rootFolder)
- default = traverse(self.rootFolder, "++etc++site/default")
- default['foo'] = Foo("local")
- foo = default['foo']
-
- for name in ('', 'bob'):
- registration = utility.UtilityRegistration(name, IFoo, foo)
- self.assertEqual(utilities.queryRegistrationsFor(registration),
- None)
- registery = utilities.createRegistrationsFor(registration)
- self.assert_(IRegistrationStack.providedBy(registery))
- self.assertEqual(utilities.queryRegistrationsFor(registration),
- registery)
-
-
- def test_local_utilities(self):
- utilityService = zapi.getGlobalService(zapi.servicenames.Utilities)
- utilityService.provideUtility(IFoo, Foo("global"))
- utilityService.provideUtility(IFoo, Foo("global bob"),
- name="bob")
-
- utilities = getService("Utilities", self.rootFolder)
-
- # We changed the root (base) service. This doesn't normally
- # occur. We have to notify the local service that the base
- # has changes:
- utilities.baseChanged()
-
- default = traverse(self.rootFolder, "++etc++site/default")
- default['foo'] = Foo("local")
- foo = default['foo']
- cm = default.getRegistrationManager()
-
- for name in ('', 'bob'):
- registration = utility.UtilityRegistration(name, IFoo, foo)
- cname = cm.addRegistration(registration)
- registration = traverse(cm, cname)
-
- gout = name and "foo global "+name or "foo global"
-
- self.assertEqual(utilities.getUtility(IFoo, name).foo(), gout)
-
- registration.status = ActiveStatus
-
- self.assertEqual(utilities.getUtility(IFoo, name).foo(),
- "foo local")
-
- registration.status = RegisteredStatus
-
- self.assertEqual(utilities.getUtility(IFoo, name).foo(), gout)
-
-
- def test_local_overrides(self):
- # Make sure that a local utility service can override another
- sm1 = zapi.traverse(self.rootFolder, "++etc++site")
- setup.addUtility(sm1, 'u1', IFoo, Foo('u1'))
- setup.addUtility(sm1, 'u2', IFoo, Foo('u2'))
- sm2 = self.makeSite('folder1')
- setup.addService(sm2, zapi.servicenames.Utilities,
- utility.LocalUtilityService())
- setup.addUtility(sm2, 'u2', IFoo, Foo('u22'))
-
- # Make sure we acquire:
- self.assertEqual(zapi.getUtility(IFoo, 'u1', sm2).name, 'u1')
-
- # Make sure we override:
- self.assertEqual(zapi.getUtility(IFoo, 'u2', sm2).name, 'u22')
-
-
-class TestLocalUtilityDirective(PlacelessSetup, unittest.TestCase):
-
- def setUp(self):
- super(TestLocalUtilityDirective, self).setUp()
- XMLConfig('meta.zcml', zope.app.component)()
- XMLConfig('meta.zcml', zope.app.utility)()
-
- def testDirective(self):
- f = configfile('''
- <localUtility
- class="zope.app.utility.tests.UtilityStub">
- </localUtility>
- ''')
- xmlconfig(f)
- self.assert_(ILocalUtility.implementedBy(UtilityStub))
- self.assert_(IAttributeAnnotatable.implementedBy(UtilityStub))
-
-
-def test_suite():
- return unittest.TestSuite((
- unittest.makeSuite(TestUtilityService),
- unittest.makeSuite(TestLocalUtilityDirective),
- DocTestSuite('zope.app.utility.metaconfigure'),
- DocTestSuite('zope.app.utility.vocabulary',
- setUp=setup.placelessSetUp,
- tearDown=setup.placelessTearDown)
- ))
-
-if __name__ == '__main__':
- unittest.main(default='test_suite')
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/tests.py (from rev 28677, Zope3/branches/srichter-blow-services/src/zope/app/utility/tests.py)
Deleted: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/utility.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/utility/utility.py 2004-12-17 21:36:22 UTC (rev 28644)
+++ Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/utility.py 2004-12-21 23:28:27 UTC (rev 28678)
@@ -1,124 +0,0 @@
-##############################################################################
-# Copyright (c) 2003 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-##############################################################################
-"""Local utility service implementation.
-
-Besides being functional, this module also serves as an example of
-creating a local service; see README.txt.
-
-$Id$
-"""
-from persistent.interfaces import IPersistent
-from zope.app.adapter.adapter import LocalAdapterService
-from zope.app import zapi
-from zope.app.registration.registration import ComponentRegistration
-from zope.app.utility.interfaces import ILocalUtilityService
-from zope.app.utility.interfaces import IUtilityRegistration
-from zope.component.utility import UtilityService
-from zope.security.proxy import removeSecurityProxy
-import zope.app.site.interfaces
-import zope.interface
-import zope.interface.adapter
-
-class LocalUtilityService(UtilityService, LocalAdapterService):
- """Local Utility Service
- """
-
- serviceType = zapi.servicenames.Utilities
-
- zope.interface.implementsOnly(
- ILocalUtilityService,
- zope.app.site.interfaces.ISimpleService,
- zope.app.site.interfaces.IBindingAware,
- IPersistent # used for IKeyReference adaption
- )
-
-
- def queryRegistrations(self, name, interface):
- return self.queryRegistrationsFor(
- UtilityRegistration(name, interface, None)
- )
-
- def getLocalUtilitiesFor(self, interface):
- # This method is deprecated and is temporarily provided for
- # backward compatability
- from zope.app import zapi
- from zope.app.component.localservice import getNextService
- next = getNextService(self, zapi.servicenames.Utilities)
- next_utils = dict(next.getUtilitiesFor(interface))
- for name, util in self.getUtilitiesFor(interface):
- if next_utils.get(name) != util:
- yield name, util
-
-
- def _updateAdaptersFromLocalData(self, adapters):
- LocalAdapterService._updateAdaptersFromLocalData(self, adapters)
-
- for required, stacks in self.stacks.iteritems():
- if required is None:
- required = Default
- radapters = adapters.get(required)
-
- for key, stack in stacks.iteritems():
- registration = stack.active()
- if registration is not None:
- key = True, key[1], '', key[3]
-
- # Needs more thought:
- # We have to remove the proxy because we're
- # storing the value amd we can't store proxies.
- # (Why can't we?) we need to think more about
- # why/if this is truly safe
-
- radapters[key] = radapters.get(key, ()) + (
- removeSecurityProxy(registration.factory), )
-
-
-
-class UtilityRegistration(ComponentRegistration):
- """Utility component registration for persistent components
-
- This registration configures persistent components in packages to
- be utilities.
- """
- zope.interface.implements(IUtilityRegistration)
-
- serviceType = zapi.servicenames.Utilities
-
- ############################################################
- # To make adapter code happy. Are we going too far?
- #
- required = zope.interface.adapter.Null
- with = ()
- provided = property(lambda self: self.interface)
- factory = property(lambda self: self.component)
- #
- ############################################################
-
- def __init__(self, name, interface, component, permission=None):
- super(UtilityRegistration, self).__init__(component, permission)
- self.name = name
- self.interface = interface
-
- def usageSummary(self):
- # Override IRegistration.usageSummary()
- s = self.getInterface().getName()
- if self.name:
- s += " registered as '%s'" % self.name
- s += ", implemented by %s" %self.component.__class__.__name__
- s += " '%s'"%zapi.name(self.component)
- return s
-
- def getInterface(self):
- # ComponentRegistration calls this when you specify a
- # permission; it needs the interface to create a security
- # proxy for the interface with the given permission.
- return self.interface
Copied: Zope3/branches/srichter-blow-services/src/zope/app/component/bbb/utility/utility.py (from rev 28677, Zope3/branches/srichter-blow-services/src/zope/app/utility/utility.py)
More information about the Zope3-Checkins
mailing list