[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ Got
local site managers working using the new registry machinery.
Jim Fulton
jim at zope.com
Sun Mar 19 12:00:47 EST 2006
Log message for revision 66074:
Got local site managers working using the new registry machinery.
The next steps are:
- Refactor application code to register things the new way.
- Make deprecation warnings go away.
- Deal with data backward compatibility
Changed:
U Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py
U Zope3/branches/jim-adapter/src/zope/app/authentication/browser/principalfolder.txt
U Zope3/branches/jim-adapter/src/zope/app/catalog/browser/README.txt
U Zope3/branches/jim-adapter/src/zope/app/component/adapter.py
U Zope3/branches/jim-adapter/src/zope/app/component/back35.py
D Zope3/branches/jim-adapter/src/zope/app/component/browser/ftests.py
U Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.py
U Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.txt
U Zope3/branches/jim-adapter/src/zope/app/component/configure.zcml
U Zope3/branches/jim-adapter/src/zope/app/component/interfaces/__init__.py
U Zope3/branches/jim-adapter/src/zope/app/component/site.py
U Zope3/branches/jim-adapter/src/zope/app/component/site.txt
U Zope3/branches/jim-adapter/src/zope/app/component/tests/deprecated35_registration.txt
U Zope3/branches/jim-adapter/src/zope/component/registry.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/appsetup/bootstrap.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -58,7 +58,7 @@
Returns the name added or ``None`` if nothing was added.
"""
sm = root_folder.getSiteManager()
- utils = [reg for reg in sm.utilities.registrations()
+ utils = [reg for reg in sm.registeredUtilities()
if reg.provided.isOrExtends(interface)]
if len(utils) == 0:
return addConfigureUtility(
Modified: Zope3/branches/jim-adapter/src/zope/app/authentication/browser/principalfolder.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/authentication/browser/principalfolder.txt 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/authentication/browser/principalfolder.txt 2006-03-19 17:00:46 UTC (rev 66074)
@@ -28,7 +28,8 @@
... Cookie: zope3_cs_6a553b3=-j7C3CdeW9sUK8BP5x97u2d9o242xMJDzJd8HCQ5AAi9xeFcGTFkAs
... Referer: http://localhost:8081/++etc++site/default/@@contents.html?type_name=BrowserAdd__zope.app.authentication.authentication.PluggableAuthentication
...
- ... type_name=BrowserAdd__zope.app.authentication.authentication.PluggableAuthentication&new_value=PAU""")
+ ... type_name=BrowserAdd__zope.app.authentication.authentication.PluggableAuthentication&new_value=PAU""",
+ ... handle_errors=False)
HTTP/1.1 303 See Other
...
Modified: Zope3/branches/jim-adapter/src/zope/app/catalog/browser/README.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/catalog/browser/README.txt 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/catalog/browser/README.txt 2006-03-19 17:00:46 UTC (rev 66074)
@@ -23,7 +23,8 @@
... Content-Type: application/x-www-form-urlencoded
... Referer: http://localhost:8081/++etc++site/default/@@+
...
- ... type_name=BrowserAdd__zope.app.intid.IntIds&id=&add=+Add+""")
+ ... type_name=BrowserAdd__zope.app.intid.IntIds&id=&add=+Add+""",
+ ... handle_errors=False)
HTTP/1.1 303 ...
And register it:
Modified: Zope3/branches/jim-adapter/src/zope/app/component/adapter.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/adapter.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/adapter.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -27,6 +27,7 @@
from zope.app.component import registration
from zope.app.component import interfaces
+from zope.app import zapi
class LocalAdapterRegistry(zope.interface.adapter.AdapterRegistry,
@@ -135,3 +136,80 @@
'component=%r, ' %self.component +
'permission=%r' %self.permission +
'>')
+
+class LocalUtilityRegistry(LocalAdapterRegistry):
+
+ zope.deprecation.deprecate(
+ "Will go away in Zope 3.5. Use registerUtility instead."
+ )
+ def register(self, registration):
+ """See zope.app.component.interfaces.registration.IRegistry"""
+ self._registrations += (registration,)
+
+ zope.interface.adapter.AdapterRegistry.register(
+ self,
+ (),
+ registration.provided, registration.name,
+ registration.component,
+ )
+
+ # XXX need test that this second part happens
+ zope.interface.adapter.AdapterRegistry.subscribe(
+ self,
+ (),
+ registration.provided,
+ registration.component,
+ )
+
+ zope.deprecation.deprecate(
+ "Will go away in Zope 3.5. Use unregisterUtility instead."
+ )
+ def unregister(self, registration):
+ """See zope.app.component.interfaces.registration.IRegistry"""
+ self._registrations = tuple([reg for reg in self._registrations
+ if reg is not registration])
+
+ zope.interface.adapter.AdapterRegistry.unregister(
+ self,
+ (),
+ registration.provided, registration.name,
+ registration.component,
+ )
+
+
+ # XXX need test that this second part happens
+ zope.interface.adapter.AdapterRegistry.unsubscribe(
+ self,
+ (),
+ registration.provided,
+ registration.component,
+ )
+
+ zope.deprecation.deprecate(
+ "Will go away in Zope 3.5. "
+ "Use registeredUtilities on site manager instead."
+ )
+ @zope.deprecation.deprecate("Will go away in Zope 3.5")
+ def registered(self, registration):
+ raise TypeError("We never supported adapters")
+
+ @zope.deprecation.deprecate("Will go away in Zope 3.5")
+ def registrations(self):
+ raise TypeError("We never supported adapters")
+
+
+class UtilityRegistration(registration.ComponentRegistration):
+ """Utility component registration for persistent components
+
+ This registration configures persistent components in packages to
+ be utilities.
+ """
+ zope.interface.implements(interfaces.IUtilityRegistration)
+
+ def __init__(self, name, provided, component, permission=None):
+ super(UtilityRegistration, self).__init__(component, permission)
+ self.name = name
+ self.provided = provided
+
+ def getRegistry(self):
+ return zapi.getSiteManager(self)
Modified: Zope3/branches/jim-adapter/src/zope/app/component/back35.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/back35.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/back35.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -22,6 +22,7 @@
from zope import interface, schema
import zope.component.interfaces
+import zope.deprecation
import zope.app.component.interfaces.registration
import zope.schema.vocabulary
from zope.app.i18n import ZopeMessageFactory as _
@@ -213,7 +214,7 @@
All registerable components need to implement this interface.
"""
- zope.app.container.constraints.containers(IRegisterableContainer)
+ #zope.app.container.constraints.containers(IRegisterableContainer)
class IRegisterableContainerContaining(
@@ -548,6 +549,7 @@
"""
implements(interfaces.IRegistrationManager)
+ zope.deprecation.deprecate("Will go away in Zope 3.5")
def addRegistration(self, reg):
"See IWriteContainer"
key = self._chooseName('', reg)
@@ -569,8 +571,6 @@
class RegisterableContainer(object):
"""Mix-in to implement `IRegisterableContainer`"""
- implements(interfaces.IRegisterableContainer,
- interfaces.IRegisterableContainerContaining)
def __init__(self):
super(RegisterableContainer, self).__init__()
@@ -598,3 +598,35 @@
if name == '':
return self.context
raise TraversalError(self.context, name)
+
+
+
+class AdapterRegistration(ComponentRegistration):
+ """Adapter component registration for persistent components
+
+ This registration configures persistent components in packages to
+ be adapters.
+ """
+ zope.interface.implements(IAdapterRegistration)
+
+ def __init__(self, required, provided, factoryName,
+ name='', permission=None):
+ if not isinstance(required, (tuple, list)):
+ self.required = required
+ self.with = ()
+ else:
+ self.required = required[0]
+ self.with = tuple(required[1:])
+ self.provided = provided
+ self.name = name
+ self.factoryName = factoryName
+ self.permission = permission
+
+ def component(self):
+ factory = resolve(self.factoryName, self)
+ return factory
+ component = property(component)
+
+ def getRegistry(self):
+ return zapi.getSiteManager(self)
+
Deleted: Zope3/branches/jim-adapter/src/zope/app/component/browser/ftests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/browser/ftests.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/browser/ftests.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -1,39 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2004 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.
-#
-##############################################################################
-"""Functional tests
-
-$Id$
-"""
-import unittest
-from zope.app.testing import functional
-
-
-class RegistrationViewTests(functional.BrowserTestCase):
-
- def testRegistrationView(self):
- response = self.publish(
- '/++etc++site/default/++registrations++/@@index.html',
- basic='mgr:mgrpw',
- handle_errors=True)
- self.assertEqual(response.getStatus(), 200)
- body = response.getBody()
- self.assert_('Registration Manager' in body)
-
-
-def test_suite():
- return unittest.makeSuite(RegistrationViewTests)
-
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Modified: Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -139,10 +139,9 @@
def toolExists(self, interface, name=''):
"""Check whether a tool already exists in this site"""
sm = zapi.getSiteManager()
- for reg in sm.registrations():
- if isinstance(reg, site.UtilityRegistration):
- if reg.name == name and reg.provided == interface:
- return True
+ for reg in sm.registeredUtilities():
+ if reg.name == name and reg.provided == interface:
+ return True
return False
def getUniqueTools(self):
@@ -258,7 +257,7 @@
"""See zope.app.container.interfaces.IAdding"""
name = self.contentName
- if self.toolExists(self.activeTool.interface,name):
+ if self.toolExists(self.activeTool.interface, name):
raise UserError(_(u'The given tool name is already being used.'))
sm = self.context
Modified: Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.txt 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/browser/tools.txt 2006-03-19 17:00:46 UTC (rev 66074)
@@ -4,22 +4,26 @@
>>> from zope import interface
+XXX There is no documentation in this doctest. :(
+
First we define a utility to work with :
>>> from zope.app.content.interfaces import IContentType
- >>> from zope.app.component.interfaces.registration import IRegisterable
>>> class IFooUtil(interface.Interface):
... pass
>>> class FooUtil(object):
... __parent__ = None
... __name__ = u''
- ... interface.implements(IFooUtil, IRegisterable, IContentType)
+ ... interface.implements(IFooUtil, IContentType)
>>> from zope.app.component.browser import tools
>>> from zope import component
+We create a tool-configuration utility that provides information for
+the the UI.
+
>>> toolConfig = tools.ToolConfiguration(IFooUtil, 'FooUtil')
- >>> component.provideUtility(toolConfig, tools.IToolConfiguration, 'IFooUtil')
+ >>> component.provideUtility(toolConfig, name='IFooUtil')
We need a factory to create our new utility :
Modified: Zope3/branches/jim-adapter/src/zope/app/component/configure.zcml
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/configure.zcml 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/configure.zcml 2006-03-19 17:00:46 UTC (rev 66074)
@@ -65,16 +65,6 @@
zope.app.container.interfaces.IWriteContainer" />
</content>
- <!-- TODO: We allow these attributes to be changed. We need some subscriber
- that updated the registries once attributes change. -->
- <content class=".site.AdapterRegistration">
- <require
- permission="zope.ManageSite"
- interface=".interfaces.IAdapterRegistration"
- set_schema=".interfaces.IAdapterRegistration"
- />
- </content>
-
<content class=".site.UtilityRegistration">
<require
permission="zope.ManageSite"
Modified: Zope3/branches/jim-adapter/src/zope/app/component/interfaces/__init__.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/interfaces/__init__.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/interfaces/__init__.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -76,8 +76,34 @@
the global site manager which contains file based utilities and adapters.
"""
+ subs = zope.interface.Attribute(
+ "A collection of registries that describe the next level "
+ "of the registry tree. They are the children of this "
+ "registry node. This attribute should never be "
+ "manipulated manually. Use `addSub()` and `removeSub()` "
+ "instead.")
+
+ def addSub(sub):
+ """Add a new sub-registry to the node.
+
+ Important: This method should *not* be used manually. It is
+ automatically called by `setNext()`. To add a new registry to the
+ tree, use `sub.setNext(self, self.base)` instead!
+ """
+
+ def removeSub(sub):
+ """Remove a sub-registry to the node.
+
+ Important: This method should *not* be used manually. It is
+ automatically called by `setNext()`. To remove a registry from the
+ tree, use `sub.setNext(None)` instead!
+ """
+
+
class ISiteManagementFolder(zope.app.container.interfaces.IContainer):
"""Component and component registration containers."""
- zope.app.container.constraints.containers(ILocalSiteManager)
+ # XXX we need to figure out how to constrain this or, alternatively,
+ # just use regular folders, which is probably the beter choice.
+ # zope.app.container.constraints.containers(ILocalSiteManager)
Modified: Zope3/branches/jim-adapter/src/zope/app/component/site.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/site.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/site.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -28,6 +28,10 @@
import zope.event
import zope.interface
import zope.component.registry
+import zope.component.persistentregistry
+import zope.deprecation
+import zope.deferredimport
+
from zope.component.interfaces import ComponentLookupError
from zope.security.proxy import removeSecurityProxy
@@ -38,9 +42,11 @@
from zope.app.component.hooks import setSite
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
+import zope.app.location
from zope.app.event import objectevent
from zope.app.filerepresentation.interfaces import IDirectoryFactory
from zope.app.traversing.interfaces import IContainmentRoot
+import zope.app.component.back35
##############################################################################
# from zope.app.module import resolve
@@ -65,7 +71,7 @@
# from zope.app.module import resolve
##############################################################################
-class SiteManagementFolder(registration.RegisterableContainer,
+class SiteManagementFolder(zope.app.component.back35.RegisterableContainer,
BTreeContainer):
zope.interface.implements(interfaces.ISiteManagementFolder)
@@ -129,86 +135,64 @@
return site.getSiteManager()
-class LocalUtilityRegistry(adapter.LocalAdapterRegistry):
- """Custom local adapter registry for utilities, since utilities do not
- just register themselves as null adapters, but also as subscribers."""
+class _LocalAdapterRegistry(
+ zope.component.persistentregistry.PersistentAdapterRegistry,
+ zope.app.location.Location,
+ ):
+ pass
- def register(self, registration):
- """See zope.app.component.interfaces.registration.IRegistry"""
- self._registrations += (registration,)
+class LocalSiteManager(BTreeContainer,
+ zope.component.persistentregistry.PersistentComponents):
+ """Local Site Manager implementation"""
+ zope.interface.implements(interfaces.ILocalSiteManager)
- zope.interface.adapter.AdapterRegistry.register(
- self,
- (),
- registration.provided, registration.name,
- registration.component,
- )
+ subs = ()
- # XXX need test that this second part happens
- zope.interface.adapter.AdapterRegistry.subscribe(
- self,
- (),
- registration.provided,
- registration.component,
- )
+ @property
+ @zope.deprecation.deprecate("Goes away in Zope 3.5. Use __bases__[0]")
+ def next(self):
+ if self.__bases__:
+ return self.__bases__[0]
- def unregister(self, registration):
- """See zope.app.component.interfaces.registration.IRegistry"""
- self._registrations = tuple([reg for reg in self._registrations
- if reg is not registration])
+ def _setBases(self, bases):
- zope.interface.adapter.AdapterRegistry.unregister(
- self,
- (),
- registration.provided, registration.name,
- registration.component,
- )
+ # Update base subs
+ for base in self.__bases__:
+ if ((base not in bases)
+ and interfaces.ILocalSiteManager.providedBy(base)
+ ):
+ base.removeSub(self)
+ for base in bases:
+ if ((base not in self.__bases__)
+ and interfaces.ILocalSiteManager.providedBy(base)
+ ):
+ base.addSub(self)
- # XXX need test that this second part happens
- zope.interface.adapter.AdapterRegistry.unsubscribe(
- self,
- (),
- registration.provided,
- registration.component,
- )
+ super(LocalSiteManager, self)._setBases(bases)
-
-class LocalSiteManager(BTreeContainer,
- zope.component.registry.Components):
- """Local Site Manager implementation"""
- zope.interface.implements(
- interfaces.ILocalSiteManager,
- interfaces.registration.IRegisterableContainerContaining)
-
- # See interfaces.registration.ILocatedRegistry
- next = None
- subs = ()
- base = None
-
def __init__(self, site):
# Locate the site manager
self.__parent__ = site
self.__name__ = '++etc++site'
- # Make sure everything is setup correctly
BTreeContainer.__init__(self)
-
- # Set up adapter registries
- gsm = zapi.getGlobalSiteManager()
- self.adapters = adapter.LocalAdapterRegistry(gsm.adapters)
- self.utilities = LocalUtilityRegistry(gsm.utilities)
-
- # Setup located registry attributes
+ zope.component.persistentregistry.PersistentComponents.__init__(self)
+
next = _findNextSiteManager(site)
- self.setNext(next)
+ if next is None:
+ next = zapi.getGlobalSiteManager()
+ self.__bases__ = (next, )
# Setup default site management folder
folder = SiteManagementFolder()
zope.event.notify(objectevent.ObjectCreatedEvent(folder))
self['default'] = folder
+ def _init_registries(self):
+ self.adapters = _LocalAdapterRegistry()
+ self.utilities = _LocalAdapterRegistry()
def addSub(self, sub):
"""See interfaces.registration.ILocatedRegistry"""
@@ -219,19 +203,9 @@
self.subs = tuple(
[s for s in self.subs if s is not sub] )
+ @zope.deprecation.deprecate("Will go away in Zope 3.5")
def setNext(self, next, base=None):
- """See interfaces.registration.ILocatedRegistry"""
- if self.next is not None:
- self.next.removeSub(self)
- if next is not None:
- next.addSub(self)
- self.next = next
- if next is not None:
- self.adapters.setNext(next.adapters)
- self.utilities.setNext(next.utilities)
- else:
- self.adapters.setNext(None)
- self.utilities.setNext(None)
+ self.__bases__ = tuple([b for b in (next, base) if b is not None])
def __getRegistry(self, registration):
"""Determine the correct registry for the registration."""
@@ -244,80 +218,109 @@
"provide `IAdapterRegistration` or "
"`IUtilityRegistration`.")
+ @zope.deprecation.deprecate(
+ "Local registration is now much simpler. The old baroque APIs "
+ "will go away in Zope 3.5. See the new component-registration APIs "
+ "defined in zope.component, especially IComponentRegistry.",
+ )
def register(self, registration):
- """See zope.app.component.interfaces.registration.IRegistry"""
- registry = self.__getRegistry(registration)
- registry.register(registration)
+ if interfaces.IUtilityRegistration.providedBy(registration):
+ self.registerUtility(
+ registration.component,
+ registration.provided,
+ registration.name,
+ )
+ elif interfaces.IAdapterRegistration.providedBy(registration):
+ self.registerAdapter(
+ registration.component,
+ (registration.required, ) + registration.with,
+ registration.provided,
+ registration.name,
+ )
+ @zope.deprecation.deprecate(
+ "Local registration is now much simpler. The old baroque APIs "
+ "will go away in Zope 3.5. See the new component-registration APIs "
+ "defined in zope.component, especially IComponentRegistry.",
+ )
def unregister(self, registration):
- """See zope.app.component.interfaces.registration.IRegistry"""
- registry = self.__getRegistry(registration)
- registry.unregister(registration)
+ if interfaces.IUtilityRegistration.providedBy(registration):
+ self.unregisterUtility(
+ registration.component,
+ registration.provided,
+ registration.name,
+ )
+ elif interfaces.IAdapterRegistration.providedBy(registration):
+ self.unregisterAdapter(
+ registration.component,
+ (registration.required, ) + registration.with,
+ registration.provided,
+ registration.name,
+ )
+ @zope.deprecation.deprecate(
+ "Local registration is now much simpler. The old baroque APIs "
+ "will go away in Zope 3.5. See the new component-registration APIs "
+ "defined in zope.component, especially IComponentRegistry.",
+ )
def registered(self, registration):
- """See zope.app.component.interfaces.registration.IRegistry"""
- return self.adapters.registered(registration) or \
- self.utilities.registered(registration)
+ if interfaces.IUtilityRegistration.providedBy(registration):
+ return bool([
+ r for r in self.registeredUtilities()
+ if (
+ r.component == registration.component
+ and
+ r.provided == registration.provided
+ and
+ r.name == registration.name
+ )
+ ])
+ elif interfaces.IAdapterRegistration.providedBy(registration):
+ return bool([
+ r for r in self.registeredAdapters()
+ if (
+ r.component == registration.component
+ and
+ r.provided == registration.provided
+ and
+ r.name == registration.name
+ and
+ r.required == ((registration.required, )
+ + registration.with)
+ )
+ ])
+ return False
def registrations(self):
"""See zope.component.interfaces.IRegistry"""
- for reg in self.adapters.registrations():
- yield reg
- for reg in self.utilities.registrations():
- yield reg
+ for r in self.registeredUtilities():
+ yield r
+ for r in self.registeredAdapters():
+ yield r
+ for r in self.registeredHandlers():
+ yield r
+ for r in self.registeredSubscriptionAdapters():
+ yield r
-class AdapterRegistration(registration.ComponentRegistration):
- """Adapter component registration for persistent components
+## zope.deferredimport.deprecatedFrom(
+## "Local registration is now much simpler. The old baroque APIs "
+## "will go away in Zope 3.5. See the new component-registration APIs "
+## "defined in zope.component, especially IComponentRegistry.",
+## 'zope.app.component.back35',
+## 'AdapterRegistration',
+## )
- This registration configures persistent components in packages to
- be adapters.
- """
- zope.interface.implements(interfaces.IAdapterRegistration)
+zope.deferredimport.deprecatedFrom(
+ "Local registration is now much simpler. The old baroque APIs "
+ "will go away in Zope 3.5. See the new component-registration APIs "
+ "defined in zope.component, especially IComponentRegistry.",
+ 'zope.app.component.adapter',
+ 'LocalAdapterRegistry', 'LocalUtilityRegistry', 'UtilityRegistration',
+ )
- def __init__(self, required, provided, factoryName,
- name='', permission=None):
- if not isinstance(required, (tuple, list)):
- self.required = required
- self.with = ()
- else:
- self.required = required[0]
- self.with = tuple(required[1:])
- self.provided = provided
- self.name = name
- self.factoryName = factoryName
- self.permission = permission
- def component(self):
-# Didn't work ... tests failed
-## # Import here, so that we only have a soft dependence on
-## # zope.app.module
-## from zope.app.module import resolve
- factory = resolve(self.factoryName, self)
- return factory
- component = property(component)
- def getRegistry(self):
- return zapi.getSiteManager(self)
-
-
-class UtilityRegistration(registration.ComponentRegistration):
- """Utility component registration for persistent components
-
- This registration configures persistent components in packages to
- be utilities.
- """
- zope.interface.implements(interfaces.IUtilityRegistration)
-
- def __init__(self, name, provided, component, permission=None):
- super(UtilityRegistration, self).__init__(component, permission)
- self.name = name
- self.provided = provided
-
- def getRegistry(self):
- return zapi.getSiteManager(self)
-
-
def threadSiteSubscriber(ob, event):
"""A subscriber to BeforeTraverseEvent
Modified: Zope3/branches/jim-adapter/src/zope/app/component/site.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/site.txt 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/site.txt 2006-03-19 17:00:46 UTC (rev 66074)
@@ -177,7 +177,7 @@
MyUtility('Global Utility')
Next let's see whether we can also successfully register an adapter as
-well. Here the adpater will provide the size of a file:
+well. Here the adapter will provide the size of a file:
>>> class IFile(zope.interface.Interface):
... pass
@@ -193,20 +193,10 @@
... def __init__(self, context):
... self.context = context
-We place the adapter in a particular module, so that adapter registration will
-be able to look it up by name.
+Now that we have the adapter we need to register it:
- >>> import sys
- >>> sys.modules['zope.app.component.tests'].FileSize = FileSize
+ >>> sm.registerAdapter(FileSize, [IFile])
-Now that we the adapter we need to register it:
-
- >>> areg = site.AdapterRegistration(IFile, ISized,
- ... 'zope.app.component.tests.FileSize')
- >>> default.registrationManager.addRegistration(areg)
- 'AdapterRegistration'
- >>> areg.status = interfaces.registration.ActiveStatus
-
Finally, we can get the adapter for a file:
>>> file = File()
@@ -343,6 +333,7 @@
# Make sure that our interfaces and classes are picklable.
+ >>> import sys
>>> sys.modules['zope.app.component.tests'].IMyUtility = IMyUtility
>>> IMyUtility.__module__ = 'zope.app.component.tests'
>>> sys.modules['zope.app.component.tests'].MyUtility = MyUtility
Modified: Zope3/branches/jim-adapter/src/zope/app/component/tests/deprecated35_registration.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/tests/deprecated35_registration.txt 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/app/component/tests/deprecated35_registration.txt 2006-03-19 17:00:46 UTC (rev 66074)
@@ -247,29 +247,6 @@
---------------
-The ++registrations++ traversal namespace
------------------------------------------
-
-To make the registration manager easier accessible via a traversal path, a
-special traversal namespace has been implemented. But first we have to
-register the traversal namespace:
-
- >>> from zope.app.traversing.interfaces import ITraversable
- >>> from zope.app.component.registration import RegistrationManagerNamespace
- >>> from zope.app.testing import ztapi
- >>> ztapi.provideAdapter(
- ... interfaces.registration.IRegisterableContainer,
- ... ITraversable,
- ... RegistrationManagerNamespace,
- ... 'registrations')
-
-Now we can use the namespace during traversal:
-
- >>> from zope.app.traversing.api import traverse
- >>> traverse(registerables, '++registrations++') is regManager
- True
-
-
The Component Registration
--------------------------
Modified: Zope3/branches/jim-adapter/src/zope/component/registry.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/component/registry.py 2006-03-19 17:00:44 UTC (rev 66073)
+++ Zope3/branches/jim-adapter/src/zope/component/registry.py 2006-03-19 17:00:46 UTC (rev 66074)
@@ -41,21 +41,23 @@
self._subscription_registrations = []
self._handler_registrations = []
+ def _getBases(self):
+ # Subclasses might override
+ return self.__dict__.get('__bases__', ())
+
+ def _setBases(self, bases):
+ # Subclasses might override
+ self.adapters.__bases__ = tuple([
+ base.adapters for base in bases])
+ self.utilities.__bases__ = tuple([
+ base.utilities for base in bases])
+ self.__dict__['__bases__'] = bases
- @apply
- def __bases__():
+ __bases__ = property(
+ lambda self: self._getBases(),
+ lambda self, bases: self._setBases(bases),
+ )
- def get_bases(self):
- return self.__dict__['__bases__']
- def set_bases(self, bases):
- self.adapters.__bases__ = tuple([
- base.adapters for base in bases])
- self.utilities.__bases__ = tuple([
- base.utilities for base in bases])
- self.__dict__['__bases__'] = bases
-
- return property(get_bases, set_bases)
-
def registerUtility(self, component, provided=None, name=u'', info=u''):
if provided is None:
provided = _getUtilityProvided(component)
More information about the Zope3-Checkins
mailing list