[Checkins] SVN: zope.app.component/trunk/src/zope/app/component/ - Remove everything that was marked as to-be-removed in 3.5
Sidnei da Silva
sidnei at enfoldsystems.com
Mon Oct 13 09:18:24 EDT 2008
Log message for revision 92115:
- Remove everything that was marked as to-be-removed in 3.5
Changed:
D zope.app.component/trunk/src/zope/app/component/adapter.py
D zope.app.component/trunk/src/zope/app/component/back35.py
D zope.app.component/trunk/src/zope/app/component/browser/registration.txt
U zope.app.component/trunk/src/zope/app/component/browser/tests.py
U zope.app.component/trunk/src/zope/app/component/configure.zcml
U zope.app.component/trunk/src/zope/app/component/interfaces/__init__.py
U zope.app.component/trunk/src/zope/app/component/interfaces/registration.py
U zope.app.component/trunk/src/zope/app/component/metadirectives.py
D zope.app.component/trunk/src/zope/app/component/registration.py
U zope.app.component/trunk/src/zope/app/component/site.py
D zope.app.component/trunk/src/zope/app/component/tests/deprecated35_registration.txt
D zope.app.component/trunk/src/zope/app/component/tests/deprecated35_statusproperty.txt
D zope.app.component/trunk/src/zope/app/component/tests/test_fields.py
U zope.app.component/trunk/src/zope/app/component/tests/test_registration.py
-=-
Deleted: zope.app.component/trunk/src/zope/app/component/adapter.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/adapter.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/adapter.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,25 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 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.
-#
-##############################################################################
-"""DEPRECATED"""
-
-import zope.deferredimport
-
-zope.deferredimport.deprecated(
- "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.",
- LocalAdapterRegistry = 'zope.app.component.site:_LocalAdapterRegistry',
- AdapterRegistration = 'zope.app.component.back35:AdapterRegistration2',
- )
-
Deleted: zope.app.component/trunk/src/zope/app/component/back35.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/back35.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/back35.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,922 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 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.
-#
-##############################################################################
-"""Features that will go away in Zope 3.5.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-import UserDict
-import warnings
-
-import persistent
-import persistent.list
-import persistent.mapping
-
-from persistent import Persistent
-
-from zope import component
-import zope.cachedescriptors.property
-import zope.event
-import zope.schema
-import zope.component.interfaces
-import zope.deprecation
-import zope.schema.vocabulary
-from zope import interface, schema
-from zope.traversing.interfaces import TraversalError
-from zope.traversing.api import getPath, getRoot, traverse
-from zope.interface import implements
-from zope.security.checker import InterfaceChecker, CheckerPublic
-from zope.security.proxy import Proxy, removeSecurityProxy
-from zope.lifecycleevent import ObjectCreatedEvent
-from zope.component.interfaces import ComponentLookupError
-from zope.configuration.fields import GlobalObject
-from zope.configuration.exceptions import ConfigurationError
-from zope.publisher.interfaces.back35 import ILayer
-
-import zope.app.component.interfaces.registration
-import zope.app.container.interfaces
-import zope.app.container.constraints
-from zope.app.component.i18n import ZopeMessageFactory as _
-from zope.app.component.interfaces import registration as interfaces
-from zope.app.container.btree import BTreeContainer
-from zope.app.container.contained import Contained
-
-InactiveStatus = _('Inactive')
-ActiveStatus = _('Active')
-
-class IRegistration(interface.Interface):
- """Registration object
-
- A registration object represents a specific registration
- decision, such as registering an adapter or defining a permission.
-
- In addition to the attributes or methods defined here,
- registration objects will include additional attributes
- identifying how they should be used. For example, a service
- registration will provide a service type. An adapter
- registration will specify a used-for interface and a provided
- interface.
- """
-
- status = schema.Choice(
- title=_("Registration status"),
- vocabulary= zope.schema.vocabulary.SimpleVocabulary(
- (zope.schema.vocabulary.SimpleTerm(InactiveStatus,
- title=InactiveStatus),
- zope.schema.vocabulary.SimpleTerm(ActiveStatus,
- title=ActiveStatus))),
- default=ActiveStatus
- )
-
-
-class IComponentRegistration(IRegistration):
- """Registration object that uses a component.
-
- An interface can optionally be specified that describes the interface the
- component provides for the registry.
-
- The interface will be used to produce a proxy for the component, if
- the permission is also specified.
- """
- component = zope.app.component.interfaces.registration.Component(
- title=_("Registration Component"),
- description=_("The component the registration is for."),
- required=True)
-
- interface = schema.Field(
- title=_("Component Interface"),
- description=_("The interface the component provides through this "
- "registration."),
- required=False,
- default=None)
-
- permission = schema.Choice(
- title=_("The permission needed to use the component"),
- vocabulary="Permissions",
- required=False
- )
-
-
-class IRegistry(zope.component.interfaces.IRegistry):
- """A component that can be configured using a registration manager."""
-
- def register(registration):
- """Register a component with the registry using a registration.
-
- Once the registration is added to the registry, it will be active. If
- the registration is already registered with the registry, this method
- will quietly return.
- """
-
- def unregister(registration):
- """Unregister a component from the registry.
-
- Unregistering a registration automatically makes the component
- inactive. If the registration is not registered, this method will
- quietly return.
- """
-
- def registered(registration):
- """Determine whether a registration is registered with the registry.
-
- The method will return a Boolean value.
- """
-
-
-class ILocatedRegistry(IRegistry):
- """A registry that is located in a tree of registries.
-
-
- """
- next = interface.Attribute(
- "Set the next local registry in the tree. This attribute "
- "represents the parent of this registry node. If the "
- "value is `None`, then this registry represents the "
- "root of the tree")
-
- subs = 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.")
-
- base = interface.Attribute(
- "Outside of the local registry tree lies the global "
- "registry, which is known as the base to every local "
- "registry in the tree.")
-
- 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!
- """
-
- def setNext(next, base=None):
- """Set the next/parent registry in the tree.
-
- This method should ensure that all relevant registies are updated
- correctly as well.
- """
-
-
-class IRegistrationManager(
- zope.app.container.interfaces.IContainerNamesContainer,
- ):
- """Manage Registrations"""
- zope.app.container.constraints.contains(IRegistration)
-
- def addRegistration(registration):
- """Add a registration to the manager.
-
- The function will automatically choose a name as which the
- registration will be known. The name of the registration inside this
- manager is returned.
- """
-
-
-class IRegistrationManagerContained(zope.app.container.interfaces.IContained):
- """Objects that can be contained by the registration manager should
- implement this interface."""
- zope.app.container.constraints.containers(IRegistrationManager)
-
-
-class IRegisterableContainer(zope.app.container.interfaces.IContainer):
- """Containers with registration managers
-
- These are site-management folders of one sort or another.
-
- The container allows clients to access the registration manager
- without knowing it's name.
-
- The registration manager container *also* supports local-module
- lookup.
- """
-
- registrationManager = schema.Field(
- title=_("Registration Manager"),
- description=_("The registration manager keeps track of all component "
- "registrations."))
-
-
-class IRegisterable(zope.app.container.interfaces.IContained):
- """Mark a component as registerable.
-
- All registerable components need to implement this interface.
- """
- #zope.app.container.constraints.containers(IRegisterableContainer)
-
-
-class IRegisterableContainerContaining(
- zope.app.container.interfaces.IContainer,
- ):
- """A container that can only contain `IRegisterable`s and
- `IRegisterableContainer`s.
-
- This interface was designed to be always used together with the
- `IRegisterableContainer`.
- """
- zope.app.container.constraints.contains(
- IRegisterable, IRegisterableContainer)
-
-
-class IRegistered(interface.Interface):
- """An object that can track down its registrations.
-
- The object need not implement this functionality itself, but must at
- least support doing so via an adapter.
- """
-
- def registrations():
- """Return a sequence of registration objects for this object."""
-
-class ILocalAdapterRegistry(IRegistry, ILocatedRegistry):
- pass
-
-class ILocalUtility(IRegisterable):
- """Local utility marker.
-
- A marker interface that indicates that a component can be used as
- a local utility.
-
- Utilities should usually also declare they implement
- IAttributeAnnotatable, so that the standard adapter to
- IRegistered can be used; otherwise, they must provide
- another way to be adaptable to IRegistered.
- """
-
-class IAdapterRegistration(IComponentRegistration):
- """Local Adapter Registration for Local Adapter Registry
-
- The adapter registration is used to provide local adapters via the
- adapter registry. It is an extended component registration, whereby the
- component is the adapter factory in this case.
- """
- required = schema.Choice(
- title = _("For interface"),
- description = _("The interface of the objects being adapted"),
- vocabulary="Interfaces",
- readonly = True,
- required=False,
- default=None)
-
- with = schema.Tuple(
- title = _("With interfaces"),
- description = _("Additionally required interfaces"),
- readonly=True,
- value_type = zope.schema.Choice(vocabulary='Interfaces'),
- required=False,
- default=())
-
- provided = schema.Choice(
- title = _("Provided interface"),
- description = _("The interface provided"),
- vocabulary="Interfaces",
- readonly = True,
- required = True)
-
- name = schema.TextLine(
- title=_(u"Name"),
- readonly=False,
- required=True,
- default=u''
- )
-
- permission = schema.Choice(
- title=_("The permission required for use"),
- vocabulary="Permission Ids",
- readonly=False,
- required=False,
- )
-
- # TODO: for now until we figure out a way to specify the factory directly
- factoryName = schema.TextLine(
- title=_(u"Factory Name"),
- readonly=False,
- required=False,
- )
-
-class IUtilityRegistration(IAdapterRegistration):
- """Utility registration object.
-
- Adapter registries are also used to to manage utilities, since utilities
- are adapters that are instantiated and have no required interfaces. Thus,
- utility registrations must fulfill all requirements of an adapter
- registration as well.
- """
-
- name = zope.schema.TextLine(
- title=_("Register As"),
- description=_("The name under which the utility will be known."),
- readonly=False,
- required=True,
- default=u''
- )
-
- provided = zope.schema.Choice(
- title=_("Provided interface"),
- description=_("The interface provided by the utility"),
- vocabulary="Utility Component Interfaces",
- readonly=True,
- required=True,
- )
-
-
-
-class RegistrationStatusProperty(object):
- """A descriptor used to implement `IRegistration`'s `status` property."""
- def __get__(self, inst, klass):
- registration = inst
- if registration is None:
- return self
-
- registry = registration.getRegistry()
- if registry and registry.registered(registration):
- return ActiveStatus
-
- return InactiveStatus
-
- def __set__(self, inst, value):
- registration = inst
- registry = registration.getRegistry()
- if registry is None:
- raise ValueError('No registry found.')
-
- if value == ActiveStatus:
- if not registry.registered(registration):
- registry.register(registration)
- zope.event.notify(
- zope.component.interfaces.Registered(registration)
- )
-
- elif value == InactiveStatus:
- if registry.registered(registration):
- registry.unregister(registration)
- zope.event.notify(
- zope.component.interfaces.Unregistered(registration)
- )
- else:
- raise ValueError(value)
-
-
-class SimpleRegistration(persistent.Persistent, Contained):
- """Registration objects that just contain registration data"""
- implements(IRegistration, IRegistrationManagerContained)
-
- # See interfaces.IRegistration
- status = RegistrationStatusProperty()
-
- def getRegistry(self):
- """See interfaces.IRegistration"""
- raise NotImplementedError(
- 'This method must be implemented by each specific regstration.')
-
-
-
-
-# Note that I could get rid of the base class below, but why bother.
-# The thing that uses it is going away too. I really have no way of
-# knowing that there aren't still registrations that use the older
-# data structures. The better approach will be to just stop using
-# registrations.
-
-NULL_COMPONENT = object()
-
-class BBBComponentRegistration(object):
-
- _BBB_componentPath = None
-
- def __init__(self, component, permission=None):
- # BBB: 12/05/2004
- if isinstance(component, (str, unicode)):
- self.componentPath = component
- else:
- # We always want to set the plain component. Untrusted code will
- # get back a proxied component anyways.
- self.component = removeSecurityProxy(component)
- if permission == 'zope.Public':
- permission = CheckerPublic
- self.permission = permission
-
- def getComponent(self):
- return self.__BBB_getComponent()
- getComponent = zope.deprecation.deprecated(getComponent,
- 'Use component directly. '
- 'The reference will be gone in Zope 3.3.')
-
- def __BBB_getComponent(self):
- if self._component is NULL_COMPONENT:
- return self.__BBB_old_getComponent(self._BBB_componentPath)
-
- # This condition should somehow make it in the final code, since it
- # honors the permission.
- if self.permission:
- checker = InterfaceChecker(self.getInterface(), self.permission)
- return Proxy(self._component, checker)
-
- return self._component
-
- def __BBB_old_getComponent(self, path):
- service_manager = component.getSiteManager(self)
-
- # Get the root and unproxy it
- if path.startswith("/"):
- # Absolute path
- root = removeAllProxies(getRoot(service_manager))
- component = traverse(root, path)
- else:
- # Relative path.
- ancestor = self.__parent__.__parent__
- component = traverse(ancestor, path)
-
- if self.permission:
- if type(component) is Proxy:
- # There should be at most one security Proxy around an object.
- # So, if we're going to add a new security proxy, we need to
- # remove any existing one.
- component = removeSecurityProxy(component)
-
- interface = self.getInterface()
-
- checker = InterfaceChecker(interface, self.permission)
-
- component = Proxy(component, checker)
-
- return component
-
- def __BBB_setComponent(self, component):
- self._BBB_componentPath = None
- self._component = component
-
- component = property(__BBB_getComponent, __BBB_setComponent)
-
- def __BBB_getComponentPath(self):
- if self._BBB_componentPath is not None:
- return self._BBB_componentPath
- return '/' + '/'.join(getPath(self.component))
-
- def __BBB_setComponentPath(self, path):
- self._component = NULL_COMPONENT
- self._BBB_componentPath = path
-
- componentPath = property(__BBB_getComponentPath, __BBB_setComponentPath)
- componentPath = zope.deprecation.deprecated(
- componentPath,
- 'Use component directly. '
- 'The reference will be gone in Zope 3.3.')
-
- def __setstate__(self, dict):
- super(BBBComponentRegistration, self).__setstate__(dict)
- # For some reason the component path is not set correctly by the
- # default __setstate__ mechanism.
- if 'componentPath' in dict:
- self._component = NULL_COMPONENT
- self._BBB_componentPath = dict['componentPath']
-
- if isinstance(self._BBB_componentPath, (str, unicode)):
- self._component = NULL_COMPONENT
-
-
-class ComponentRegistration(BBBComponentRegistration,
- SimpleRegistration):
- """Component registration.
-
- Subclasses should define a getInterface() method returning the interface
- of the component.
- """
- implements(IComponentRegistration)
-
- def __init__(self, component, permission=None):
- super(ComponentRegistration, self).__init__(component, permission)
- if permission == 'zope.Public':
- permission = CheckerPublic
- self.permission = permission
-
- def _getComponent(self):
- if self.permission and self.interface:
- checker = InterfaceChecker(self.interface, self.permission)
- return Proxy(self._component, checker)
- return self._component
-
- def _setComponent(self, component):
- # We always want to set the plain component. Untrusted code will
- # get back a proxied component anyways.
- self._component = removeSecurityProxy(component)
-
- # See zope.app.component.interfaces.registration.IComponentRegistration
- component = property(_getComponent, _setComponent)
-
- # See zope.app.component.interfaces.registration.IComponentRegistration
- interface = None
-
-class Registered:
- """An adapter from IRegisterable to IRegistered.
-
- This class is the only place that knows how 'Registered'
- data is represented.
- """
- implements(IRegistered)
- __used_for__ = IRegisterable
-
- def __init__(self, registerable):
- self.registerable = registerable
-
- def registrations(self):
- context = self.registerable
- return [
- r
- for r in component.getSiteManager(context).registeredUtilities()
- if r.component == context
- ]
-
-
-class RegistrationManager(BTreeContainer):
- """Registration manager
-
- Manages registrations within a package.
- """
- implements(IRegistrationManager)
-
- @zope.deprecation.deprecate("Will go away in Zope 3.5")
- def addRegistration(self, reg):
- "See IWriteContainer"
- key = self._chooseName('', reg)
- self[key] = reg
- return key
-
- def _chooseName(self, name, reg):
- """Choose a name for the registration."""
- if not name:
- name = reg.__class__.__name__
-
- i = 1
- chosenName = name
- while chosenName in self:
- i += 1
- chosenName = name + str(i)
-
- return chosenName
-
-class RegisterableContainer(object):
- """Mix-in to implement `IRegisterableContainer`"""
-
- def __init__(self):
- super(RegisterableContainer, self).__init__()
- self.__createRegistrationManager()
-
- def __createRegistrationManager(self):
- "Create a registration manager and store it as `registrationManager`"
- # See interfaces.IRegisterableContainer
- self.registrationManager = RegistrationManager()
- self.registrationManager.__parent__ = self
- self.registrationManager.__name__ = '++registrations++'
- zope.event.notify(ObjectCreatedEvent(self.registrationManager))
-
-
-class RegistrationManagerNamespace:
- """Used to traverse to a Registration Manager from a
- Registerable Container."""
- __used_for__ = IRegisterableContainer
-
- def __init__(self, ob, request=None):
- self.context = ob.registrationManager
-
- @zope.deprecation.deprecate(
- "++registration++ namespace is deprecated and will go away in Zope 3.5"
- )
- def traverse(self, name, ignore):
- 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 component.getSiteManager(self)
-
-class AdapterRegistration2(ComponentRegistration):
- """A simple implementation of the adapter registration interface."""
- interface.implements(IAdapterRegistration)
-
- def __init__(self, required, provided, factory,
- name='', permission=None, registry=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.component = factory
- self.permission = permission
- self.registry = registry
-
- def getRegistry(self):
- return self.registry
-
- def __repr__(self):
- return ('<%s: ' %self.__class__.__name__ +
- 'required=%r, ' %self.required +
- 'with=' + `self.with` + ', ' +
- 'provided=%r, ' %self.provided +
- 'name=%r, ' %self.name +
- 'component=%r, ' %self.component +
- 'permission=%r' %self.permission +
- '>')
-
-class UtilityRegistration(ComponentRegistration):
- """Utility component registration for persistent components
-
- This registration configures persistent components in packages to
- be utilities.
- """
- interface.implements(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 component.getSiteManager(self)
-
-
-class LayerField(GlobalObject):
- r"""This field represents a layer.
-
- Besides being able to look up the layer by importing it, we also try
- to look up the name in the site manager.
-
- >>> from zope.interface import directlyProvides
- >>> from zope.interface.interface import InterfaceClass
-
- >>> layer1 = InterfaceClass('layer1', (),
- ... __doc__='Layer: layer1',
- ... __module__='zope.app.layers')
- >>> directlyProvides(layer1, ILayer)
-
- >>> layers = None
- >>> class Resolver(object):
- ... def resolve(self, path):
- ... if '..' in path:
- ... raise ValueError('Empty module name')
- ... if (path.startswith('zope.app.layers') and
- ... hasattr(layers, 'layer1') or
- ... path == 'zope.app.component.fields.layer1' or
- ... path == '.fields.layer1'):
- ... return layer1
- ... raise ConfigurationError('layer1')
-
- >>> field = LayerField()
- >>> field = field.bind(Resolver())
-
- Test 1: Import the layer
- ------------------------
-
- >>> field.fromUnicode('zope.app.component.fields.layer1') is layer1
- True
-
- Test 2: We have a shortcut name. Import the layer from `zope.app.layers`.
- -------------------------------------------------------------------------
-
- >>> from types import ModuleType as module
- >>> import sys
- >>> layers = module('layers')
- >>> import zope.app.layers
- >>> old = sys.modules['zope.app.layers']
- >>> sys.modules['zope.app.layers'] = layers
- >>> setattr(layers, 'layer1', layer1)
-
- >>> field.fromUnicode('layer1') is layer1
- True
-
- >>> sys.modules['zope.app.layers'] = old
-
- Test 3: Get the layer from the site manager
- -------------------------------------------
-
- >>> from zope.app.testing import ztapi
- >>> ztapi.provideUtility(ILayer, layer1, 'layer1')
-
- >>> field.fromUnicode('layer1') is layer1
- True
-
- Test 4: Import the layer by using a short name
- ----------------------------------------------
-
- >>> field.fromUnicode('.fields.layer1') is layer1
- True
- """
-
- def fromUnicode(self, u):
- name = str(u.strip())
-
- try:
- value = zope.component.queryUtility(ILayer, name)
- except ComponentLookupError:
- # The component architecture is not up and running.
- pass
- else:
- if value is not None:
- return value
-
- try:
- value = self.context.resolve('zope.app.layers.'+name)
- except (ConfigurationError, ValueError), v:
- try:
- value = self.context.resolve(name)
- except ConfigurationError, v:
- raise zope.schema.ValidationError(v)
-
- self.validate(value)
- return value
-
-
-class LocalSiteGeneration3SupportMixin:
-
- @zope.cachedescriptors.property.readproperty
- def _utility_registrations(self):
- return _OldUtilityRegistrations(
- self, 'utilities', '_utility_registrations')
-
- @zope.cachedescriptors.property.readproperty
- def _adapter_registrations(self):
- return _OldAdapterRegistrations(
- self, 'adapters', '_adapter_registrations')
-
- @zope.cachedescriptors.property.readproperty
- def _subscription_registrations(self):
- return _OldSubscriberRegistrations(self, '_subscription_registrations')
-
- @zope.cachedescriptors.property.readproperty
- def _handler_registrations(self):
- return _OldSubscriberRegistrations(self, '_handler_registrations')
-
- def _evolve_to_generation_4(self):
- self._utility_registrations.update(())
- self._adapter_registrations.update(())
- self._subscription_registrations.extend(())
- self._handler_registrations.extend(())
- for sub in self.subs:
- sub._evolve_to_generation_4()
-
-
-class _OldUtilityRegistrations(UserDict.DictMixin):
-
- def __init__(self, site, rname, name):
- self.site = site
- self.rname = rname
- self.__name__ = name
-
- def _getOldRegistrations(self):
- return getattr(self.site, self.rname)._registrations
-
- def __getitem__(self, key):
- (provided, name) = key
- for r in self._getOldRegistrations():
- if r.name == name and r.provided == provided:
- return r.component, u''
- raise KeyError, key
-
- def keys(self):
- return [
- (r.provided, r.name)
- for r in self._getOldRegistrations()
- ]
-
- def update(self, other):
- newregistrations = persistent.mapping.PersistentMapping()
- for r in self._getOldRegistrations():
- newregistrations[(r.provided, r.name)] = r.component, u''
-
- # finish the conversion of the utilities:
- del getattr(self.site, self.rname)._registrations
-
- for key, value in dict(other).iteritems():
- newregistrations[key] = value
-
- setattr(self.site, self.__name__, newregistrations)
-
- def __setitem__(self, k, v):
- self.update([(k, v)])
-
- def __delitem__(self, k):
- self.update(())
- del getattr(self.site, self.__name__)[k]
-
-class _OldAdapterRegistrations(_OldUtilityRegistrations):
-
- def _getOldRegistrations(self):
- if self.site.adapters._registrations:
- warnings.warn(
- "Old non-utility registrations are not supported and will not "
- "be converted",
- DeprecationWarning)
- return ()
-
-
-class _OldSubscriberRegistrations(object):
-
- def __init__(self, site, name):
- self.site = site
- self.__name__ = name
-
- def __iter__(self):
- return iter(())
-
- def __setslice__(self, i, j, other):
- assert i == 0
- self.extend(other)
-
- def extend(self, other):
- assert not other
- setattr(self.site, self.__name__, persistent.list.PersistentList())
-
- def append(self, value):
- setattr(self.site, self.__name__,
- persistent.list.PersistentList([value]),
- )
-
-class _LocalAdapterRegistryGeneration3SupportMixin(object):
-
- def __setstate__(self, state):
- if '_registrations' in state:
- # convert data to generation 3 data structure:
- next = state.get('next')
- if next is None:
- next = state['base']
- bases = (next, )
- self.__init__(bases)
- registrations = []
- for r in state['_registrations']:
- if isinstance(r, UtilityRegistration):
- self.register((), r.provided, r.name, r.component)
-
- if not [
- 1 for rseen in registrations
- if rseen.provided == r.provided
- and rseen.component == r.component
- ]:
- self.subscribe((), r.provided, r.component)
-
- registrations.append(r)
- else:
- warnings.warn(
- "Old %s registrations are not supported and will not "
- "be converted" % r.__class__.__name__,
- DeprecationWarning)
-
- self._registrations = tuple(registrations)
- else:
- super(_LocalAdapterRegistryGeneration3SupportMixin, self
- ).__setstate__(state)
-
Deleted: zope.app.component/trunk/src/zope/app/component/browser/registration.txt
===================================================================
--- zope.app.component/trunk/src/zope/app/component/browser/registration.txt 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/browser/registration.txt 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,258 +0,0 @@
-======================
-Component registration
-======================
-
-Registration of objects as components is quite simple. Currently, any
-object can be registered as a utility. (In the future, registering
-objects as adapter factories probably will be supported, but only if
-those objects implement interfaces.)
-
-To see how this works, we'll create some objects and register
-them. We'll use the Sample class defined in
-zope.app.component.browser.tests to define 3 sample objects:
-
- >>> from zope.app.component.browser.tests import Sample
- >>> folder = getRootFolder()
- >>> folder['sample1'] = Sample()
- >>> folder['sample2'] = Sample()
- >>> folder['sample3'] = Sample()
- >>> import transaction
- >>> transaction.commit()
-
-All objects have a "Registration" tab that is accessable to people
-with the zope.ManageSite permission:
-
- >>> from zope.testbrowser.testing import Browser
- >>> browser = Browser()
- >>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
- >>> browser.addHeader('Accept-Language', 'test')
- >>> browser.open('http://localhost/sample1/@@SelectedManagementView.html')
- >>> browser.getLink('[[zope][Registration]]').click()
-
-When we first visit the registration tab, we see that there are no
-registrations:
-
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][This object isn't yet registered.]]...
-
-To add a registration, we'll click on the `Register this object`
-button:
-
- >>> browser.getControl('Register this object').click()
-
-This will being up a form that provides for selection from the
-interfaces the object provides and provides and entries for name to
-provide the object as and a comment:
-
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][Provided interface]]...
- ...[[zope][The interface provided by the utility]]...
- <option value="...ISample">....ISample</option>
- <option value="...ISampleBase">...ISampleBase</option>
- <option value="...IContained">...IContained</option>
- <option value="...ILocation">...ILocation</option>
- <option value="...IPersistent">...IPersistent</option>
- <option value="...Interface">...Interface</option>
- ...[[zope][Register As]]...
- ...[[zope][The name under which the utility will be known.]]...
- ...[[zope][Comment]]...
-
-The most specific interface is selected, which is usually what we
-want. If we just enter a comment and submit the form:
-
- >>> browser.getControl('[[zope][Comment]]').value = 'unnamed sample'
- >>> browser.getControl('[[zope][Register]]').click()
-
-We'll be redirected to the registrations page and the new registration
-will be shown:
-
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][zope.app.component.browser.tests.ISample utility]]
- <br />
- [[zope][comment: unnamed sample]]...
-
-We can create multiple registrations by clicking on *Register this
-object again*:
-
- >>> browser.getControl('Register this object again').click()
- >>> browser.getControl('[[zope][Register As]]').value = 'one'
- >>> browser.getControl('[[zope][Register]]').click()
-
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][zope.app.component.browser.tests.ISample utility]]
- <br />
- [[zope][comment: unnamed sample]]...
- ...[[zope][zope.app.component.browser.tests.ISample utility named 'one']]...
-
-Each entry has a checkbox for selecting it. This can be used to
-unregister an object. We'll unregister the utility named "one":
-
- >>> browser.getControl(name='ids:list').getControl(
- ... value='Rem9wZS5hcHAuY29tcG9uZW50LmJyb3dzZXIudGVzdHMuSVNhbXBsZSBvbmU'
- ... ).selected = True
- >>> browser.getControl('[[zope][unregister-button (Unregister)]]').click()
- >>> "utility named 'one'" not in browser.contents
- True
-
-If there is already an object registered, new registrations will
-simply override the old. We can see this by creating a registration
-for sample2 and then overriding it's registration by registering
-sample3. First, we register sample2:
-
- >>> browser.open('http://localhost/sample2/registration.html')
- >>> browser.getControl('Register this object').click()
- >>> browser.getControl('[[zope][Register As]]').value = 'two'
- >>> browser.getControl('[[zope][Register]]').click()
-
-We can see all of the registrations for a site by visting the
-site-manager's registrations page:
-
- >>> browser.open(
- ... 'http://localhost/++etc++site/@@SelectedManagementView.html')
- >>> browser.getLink('[[zope][Registrations]]').click()
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][Registrations for this site: (
- Registrations for this site:
- )]]...
- ...sample1...[[zope][zope.app.component.browser.tests.ISample utility]]
- <br />
- [[zope][comment: unnamed sample]]...
- ...sample2...[[zope][zope.app.component.browser.tests.ISample
- utility named 'two']]...
-
-This shows all of the registrations for the site, including our sample
-registrations. The display includes a link to each component. Now,
-we'll register sample 3:
-
- >>> browser.open('http://localhost/sample3/registration.html')
- >>> browser.getControl('Register this object').click()
- >>> browser.getControl('[[zope][Register As]]').value = 'two'
- >>> browser.getControl('[[zope][Register]]').click()
-
-and note that now sample 3, rather than sample 2 is shown in the
-listing of registered components for the site:
-
- >>> browser.open('http://localhost/++etc++site/@@registrations.html')
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][Registrations for this site: (
- Registrations for this site:
- )]]...
- ...sample1...[[zope][zope.app.component.browser.tests.ISample utility]]
- <br />
- [[zope][comment: unnamed sample]]...
- ...sample3...[[zope][zope.app.component.browser.tests.ISample
- utility named 'two']]...
-
- >>> 'sample2' not in browser.contents
- True
-
-And if we look at sample2's registrations, we'll see it's not registered:
-
- >>> browser.open('http://localhost/sample2/registration.html')
- >>> print browser.contents
- <!DOCTYPE html ...
- ...This object isn't yet registered...
-
-Each entry in the site registrations view has a checkbox for selecting
-it. This can be used to unregister an object. We'll unregister sample3:
-
- >>> browser.open('http://localhost/++etc++site/@@registrations.html')
- >>> browser.getControl(name='ids:list').getControl(
- ... value='Rem9wZS5hcHAuY29tcG9uZW50LmJyb3dzZXIudGVzdHMuSVNhbXBsZSB0d28'
- ... ).selected = True
- >>> browser.getControl('[[zope][unregister-button (Unregister)]]').click()
- >>> 'sample3' not in browser.contents
- True
-
- >>> browser.open('http://localhost/sample3/registration.html')
- >>> print browser.contents
- <!DOCTYPE html ...
- ...This object isn't yet registered...
-
-If a registered object is deleted:
-
- >>> del folder['sample1']
- >>> transaction.commit()
-
-It remains registered, and can be unregistered:
-
- >>> browser.open('http://localhost/++etc++site/@@registrations.html')
- >>> print browser.contents
- <!DOCTYPE html ...
- ...[[zope][Registrations for this site: (
- Registrations for this site:
- )]]...
- ...[[zope][[[zope][(unknown name)]] (moved or deleted) (
- [[zope][(unknown name)]]
- (moved or deleted)
- )]]
- <br />
- [[zope][zope.app.component.browser.tests.ISample utility]]
- <br />
- [[zope][comment: unnamed sample]]...
-
- >>> browser.getControl(name='ids:list').getControl(
- ... value="Rem9wZS5hcHAuY29tcG9uZW50LmJyb3dzZXIudGVzdHMuSVNhbXBsZSA"
- ... ).selected = True
- >>> browser.getControl('[[zope][unregister-button (Unregister)]]').click()
-
- >>> 'ISample' not in browser.contents
- True
-
-The registration view for an object only shows the registrations in
-the immediately enclosing site. To see this, we register sample2:
-
- >>> browser.open('http://localhost/sample2/registration.html')
- >>> browser.getControl('Register this object').click()
- >>> browser.getControl('[[zope][Register]]').click()
-
-Now we'll create a subsite and move sample2 there:
-
- >>> browser.open('http://localhost/@@SelectedManagementView.html')
- >>> browser.getLink('[[zope][Folder]]').click()
- >>> browser.getControl(name='new_value').value = 'subsite'
- >>> browser.getControl('Apply').click()
- >>> browser.getLink('subsite').click()
- >>> browser.getLink('[[zope][Make a site]').click()
- >>> browser.open('http://localhost/@@SelectedManagementView.html')
- >>> browser.getControl(name='ids:list').getControl(value='sample2'
- ... ).selected = True
- >>> browser.getControl('[[zope][container-cut-button (Cut)]]').click()
- >>> browser.getLink('subsite').click()
- >>> browser.getControl('[[zope][container-paste-button (Paste)]]').click()
-
-sample2's registration page now indicates that sample2 is
-unregistered:
-
- >>> browser.open('http://localhost/subsite/registration.html')
- >>> print browser.contents
- <!DOCTYPE html ...
- ...This object isn't yet registered...
-
-which it is in it's new site.
-
-If we go back to the old site though, we see that sample2 is still
-registered there and that it's link points to it's new location:
-
- >>> browser.open('http://localhost/++etc++site/@@registrations.html')
- >>> print browser.contents
- <!DOCTYPE html ...
- ...subsite/sample2...zope.app.component.browser.tests.ISample utility...
-
-Of course, this could stand some improvement:
-
-- It would be nice if people were warned when overriding a component
-
-- It would be nice if people were warned when moving a registered
- component out its site. Perhaps people should be offered the option of
- unregistering it, and perhaps registering it in the new location.
-
-- It would be nice if people were warned when deleting a registered
- component. Perhaps people should be offered the option of
- unregistering it.
Modified: zope.app.component/trunk/src/zope/app/component/browser/tests.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/browser/tests.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/browser/tests.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -42,11 +42,7 @@
"site.txt",
optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
site.layer = AppComponentBrowserLayer
- reg = zope.app.testing.functional.FunctionalDocFileSuite(
- 'registration.txt',
- optionflags=doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE)
- reg.layer = AppComponentLayer
- return unittest.TestSuite((site, reg))
+ return unittest.TestSuite((site,))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
Modified: zope.app.component/trunk/src/zope/app/component/configure.zcml
===================================================================
--- zope.app.component/trunk/src/zope/app/component/configure.zcml 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/configure.zcml 2008-10-13 13:18:24 UTC (rev 92115)
@@ -2,36 +2,6 @@
<interface interface="zope.interface.Interface" />
-
- <!-- Registration Framework Goes away in 3.5-->
- <class class=".back35.RegistrationManager">
- <implements
- interface="zope.annotation.interfaces.IAttributeAnnotatable"
- />
- <require
- permission="zope.ManageSite"
- interface="zope.app.container.interfaces.IWriteContainer
- zope.app.container.interfaces.IReadContainer
- zope.app.container.interfaces.INameChooser"
- attributes="addRegistration"
- />
- </class>
-
- <!-- ++registrations++ namespace registrations -->
- <view
- name="registrations" type="*"
- for=".back35.IRegisterableContainer"
- provides="zope.traversing.interfaces.ITraversable"
- factory=".back35.RegistrationManagerNamespace"
- />
- <adapter
- name="registrations"
- for=".back35.IRegisterableContainer"
- provides="zope.traversing.interfaces.ITraversable"
- factory=".back35.RegistrationManagerNamespace"
- />
-
-
<!-- Site and Site Manager Framework -->
<module module=".interfaces">
Modified: zope.app.component/trunk/src/zope/app/component/interfaces/__init__.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/interfaces/__init__.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/interfaces/__init__.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -21,20 +21,8 @@
import zope.component.interfaces
import zope.app.container.interfaces
-import zope.deferredimport
-
from zope.location.interfaces import IPossibleSite, ISite
-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',
- 'ILocalAdapterRegistry', 'ILocalUtility', 'IAdapterRegistration',
- 'IUtilityRegistration',
- )
-
-
class INewLocalSite(zope.interface.Interface):
"""Event: a local site was created
"""
Modified: zope.app.component/trunk/src/zope/app/component/interfaces/registration.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/interfaces/registration.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/interfaces/registration.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -18,36 +18,6 @@
from zope import interface, schema
import zope.schema.interfaces
-import zope.deferredimport
-
-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',
- 'IRegistration',
- 'InactiveStatus',
- 'ActiveStatus',
- 'IComponentRegistration',
- 'IRegistry',
- 'ILocatedRegistry',
- 'IRegistrationManager',
- 'IRegistrationManagerContained',
- 'IRegisterableContainer',
- 'IRegisterable',
- 'IRegisterableContainerContaining',
- 'IRegistered',
- )
-
-zope.deferredimport.deprecated(
- "Registration events are not defined in zope.component.interfaces. "
- "Importing them from zope.app.component.registration will be disallowed "
- "in Zope 3.5",
- IRegistrationEvent = 'zope.component.interfaces:IRegistrationEvent',
- IRegistrationActivatedEvent = 'zope.component.interfaces:IRegistered',
- IRegistrationDeactivatedEvent = 'zope.component.interfaces:IUnregistered',
- )
-
class IComponent(zope.schema.interfaces.IField):
"""A component
Modified: zope.app.component/trunk/src/zope/app/component/metadirectives.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/metadirectives.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/metadirectives.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -23,7 +23,6 @@
import zope.schema
from zope.component.zcml import IBasicComponentInformation
-from zope.app.component.back35 import LayerField
from zope.app.component.i18n import ZopeMessageFactory as _
class IDefaultViewName(zope.interface.Interface):
@@ -58,7 +57,7 @@
required=False,
)
- layer = LayerField(
+ layer = zope.configuration.fields.GlobalInterface(
title=_("The layer the view is in."),
description=_("""
A skin is composed of layers. It is common to put skin
@@ -202,7 +201,7 @@
IBasicResourceInformation):
"""Register a resource"""
- layer = LayerField(
+ layer = zope.configuration.fields.GlobalInterface(
title=_("The layer the resource is in."),
required=False,
)
Deleted: zope.app.component/trunk/src/zope/app/component/registration.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/registration.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/registration.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,44 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 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.
-#
-##############################################################################
-"""Component registration support
-
-$Id$
-"""
-
-import zope.deferredimport
-
-zope.deferredimport.deprecatedFrom(
- """The old registration APIs, are deprecated and will go away in Zope 3.5
-
- See the newer component-registration APIs in
- zope.component.interfaces.IComponentRegistry.
- """,
- "zope.app.component.back35",
- 'RegistrationStatusProperty',
- 'SimpleRegistration',
- 'ComponentRegistration',
- 'Registered',
- 'RegistrationManager',
- 'RegisterableContainer',
- 'RegistrationManagerNamespace',
- )
-
-zope.deferredimport.deprecated(
- "Registration events are now defined in zope.component.interfaces. "
- "Importing them from zope.app.component.registration will be disallowed "
- "in Zope 3.5",
- RegistrationEvent = 'zope.component.interfaces:RegistrationEvent',
- RegistrationActivatedEvent = 'zope.component.interfaces:Registered',
- RegistrationDeactivatedEvent = 'zope.component.interfaces:Unregistered',
- )
Modified: zope.app.component/trunk/src/zope/app/component/site.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/site.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/site.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -31,7 +31,6 @@
import zope.component.persistentregistry
import zope.component.interfaces
import zope.traversing.api
-import zope.deprecation
import zope.deferredimport
import zope.location
@@ -40,9 +39,7 @@
from zope.lifecycleevent import ObjectCreatedEvent
from zope.filerepresentation.interfaces import IDirectoryFactory
-import zope.app.component.back35
from zope.app.component import interfaces
-from zope.app.component import registration
from zope.app.component.hooks import setSite
from zope.app.container.btree import BTreeContainer
from zope.app.container.contained import Contained
@@ -70,8 +67,7 @@
# from zope.app.module import resolve
##############################################################################
-class SiteManagementFolder(zope.app.component.back35.RegisterableContainer,
- BTreeContainer):
+class SiteManagementFolder(BTreeContainer):
zope.interface.implements(interfaces.ISiteManagementFolder)
@@ -135,7 +131,6 @@
class _LocalAdapterRegistry(
- zope.app.component.back35._LocalAdapterRegistryGeneration3SupportMixin,
zope.component.persistentregistry.PersistentAdapterRegistry,
zope.location.Location,
):
@@ -143,7 +138,6 @@
class LocalSiteManager(
BTreeContainer,
- zope.app.component.back35.LocalSiteGeneration3SupportMixin,
zope.component.persistentregistry.PersistentComponents,
):
"""Local Site Manager implementation"""
@@ -151,12 +145,6 @@
subs = ()
- @property
- @zope.deprecation.deprecate("Goes away in Zope 3.5. Use __bases__[0]")
- def next(self):
- if self.__bases__:
- return self.__bases__[0]
-
def _setBases(self, bases):
# Update base subs
@@ -208,10 +196,6 @@
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):
- 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."""
if interfaces.IUtilityRegistration.providedBy(registration):
@@ -223,150 +207,6 @@
"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):
- 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,
- )
- try:
- f = registration.activated
- except AttributeError:
- pass
- else:
- f()
-
- @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):
- 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,
- )
- try:
- f = registration.deactivated
- except AttributeError:
- pass
- else:
- f()
-
- @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):
- if zope.component.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 zope.component.interfaces.IAdapterRegistration.providedBy(
- registration):
- return bool([
- r for r in self.registeredAdapters()
- if (
- r.factory == registration.component
- and
- r.provided == registration.provided
- and
- r.name == registration.name
- and
- r.required == ((registration.required, )
- + registration.with)
- )
- ])
- elif (
- zope.component.interfaces.ISubscriptionAdapterRegistration.providedBy(
- registration)):
- return bool([
- r for r in self.registeredSubscriptionAdapters()
- if (
- r.factory == registration.component
- and
- r.provided == registration.provided
- and
- r.name == registration.name
- and
- r.required == ((registration.required, )
- + registration.with)
- )
- ])
- elif zope.component.interfaces.IHandlerRegistration.providedBy(
- registration):
- return bool([
- r for r in self.registeredHandlers()
- if (
- r.factory == registration.component
- and
- r.provided == registration.provided
- and
- r.name == registration.name
- and
- r.required == ((registration.required, )
- + registration.with)
- )
- ])
- return False
-
- @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 registrations(self):
- """See zope.component.interfaces.IRegistry"""
- 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
-
-zope.deferredimport.deprecated(
- "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.",
- LocalAdapterRegistry = 'zope.app.component.site:_LocalAdapterRegistry',
- LocalUtilityRegistry = 'zope.app.component.site:_LocalAdapterRegistry',
- UtilityRegistration = 'zope.app.component.back35:UtilityRegistration',
- AdaptersRegistration = 'zope.app.component.back35:AdaptersRegistration',
- )
-
def threadSiteSubscriber(ob, event):
"""A subscriber to BeforeTraverseEvent
Deleted: zope.app.component/trunk/src/zope/app/component/tests/deprecated35_registration.txt
===================================================================
--- zope.app.component/trunk/src/zope/app/component/tests/deprecated35_registration.txt 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/tests/deprecated35_registration.txt 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,344 +0,0 @@
-==========================
-The Registration Framework
-==========================
-
-The registration framework's task is to manage registrations and ensure that
-the correct registrations are inserted into the correct registries. Each
-registration knows to which registry it belongs. If a registration is set
-active, then the registration is added to the regstry; when inactive, it is
-removed from the registry. Please see `statusproperty.txt` for a demonstration
-on how the setting of the registration's status affects the registry.
-
-The true power of the registration framework, however, comes from the ability
-to provide registrations for registerable components. In the context of Zope
-3's component architecture, registerable components are adapters and
-utilities. Since the registration framework can be used for any kind of
-component registration, I am going to refer to registerable components
-(including adapters and interface) as components.
-
-The first task is to create a simple component registry. It will implement all
-required `IRegistry` methods and a `getComponents()` method, which will return
-a list of all registered (active) components.
-
- >>> import zope.interface
- >>> from zope.app.component import interfaces
- >>> class ComponentRegistry(object):
- ... zope.interface.implements(interfaces.registration.IRegistry)
- ...
- ... def __init__(self):
- ... self._registrations = []
- ...
- ... def registrations(self):
- ... """See zope.component.interfaces.IRegistry"""
- ... return self._registrations
- ...
- ... registeredUtilities = registrations
- ...
- ... def register(self, registration):
- ... """See interfaces.registration.IRegistry"""
- ... self._registrations.append(registration)
- ...
- ... def unregister(self, registration):
- ... """See interfaces.registration.IRegistry"""
- ... del self._registrations[self._registrations.index(registration)]
- ...
- ... def registered(self, registration):
- ... """See interfaces.registration.IRegistry"""
- ... return registration in self._registrations
- ...
- ... def getComponents(self):
- ... return [reg.component for reg in self.registrations()]
-
- >>> registry = ComponentRegistry()
-
-Effectively, a registry manages a set of active registrations. A simple
-UML diagram would be::
-
- ---------------------------
- --------------- * 1 | IRegistration |
- | IRegistry |-------| - - - - - - - - - - - - |
- --------------- | status = ActiveStatus |
- ---------------------------
-
-Next we need to create a registration object that can register components with
-our new registry. The framework already provides a base-class for
-component-based registrations, so that we only need to implement the
-`getRegistry()` method:
-
- >>> from zope.app.component.registration import ComponentRegistration
- >>> class Registration(ComponentRegistration):
- ...
- ... def getRegistry(self):
- ... global registry
- ... return registry
- ...
- ... def __repr__(self):
- ... return "<Registration for '%s'>" %self.component
-
-In the implementation above, all `Registration` instances are simply going to
-use the global `registry` object. Now that we have a registry and a suitable
-registration class, let's test what we have so far. To do that we have to
-create a component that we would like to register:
-
- >>> import zope.component.interfaces
- >>> from zope.app.container.contained import Contained
- >>> class Component(Contained):
- ... zope.interface.implements(interfaces.registration.IRegisterable)
- ... def __init__(self, title=u''):
- ... self.title = title
- ... def __repr__(self):
- ... return "<Component: '%s'>" %self.title
- ...
- ... def __conform__(self, iface):
- ... if iface == zope.component.interfaces.IComponentLookup:
- ... return registry
-
-Note that `Contained` is used as a base class, since `IRegisterable` requires
-it to be. We will later see why this is the case.
-
-Before we are registering any component, the registry is empty:
-
- >>> registry.getComponents()
- []
-
-Now we create a component and a registration:
-
- >>> foo = Component('Foo')
- >>> regFoo = Registration(foo)
- >>> regFoo.component
- <Component: 'Foo'>
- >>> regFoo.status
- u'Inactive'
-
-Finally, we activate the registration:
-
-
- >>> regFoo.status = interfaces.registration.ActiveStatus
- >>> regFoo.status
- u'Active'
- >>> registry.getComponents()
- [<Component: 'Foo'>]
-
-Of course, we can add a second registered component:
-
- >>> bar = Component('Bar')
- >>> regBar = Registration(bar)
- >>> regBar.component
- <Component: 'Bar'>
- >>> regBar.status
- u'Inactive'
- >>> regBar.status = interfaces.registration.ActiveStatus
- >>> regBar.status
- u'Active'
- >>> registry.getComponents()
- [<Component: 'Foo'>, <Component: 'Bar'>]
-
-Of course, when deactivating a registration, it will be gone from the registry
-as well:
-
- >>> regFoo.status = interfaces.registration.InactiveStatus
- >>> regFoo.status
- u'Inactive'
- >>> registry.getComponents()
- [<Component: 'Bar'>]
-
-This is everything that there is about registrations and their interaction
-with a registry. However, the point of registrations and registerable
-components is that they should be persistent (otherwise we could use
-ZCML). Thus we need a way of managing local components and their
-registrations.
-
-
-Management of Local Components and Registrations
-------------------------------------------------
-
-The starting point here is the `IRegisterableContainer`, which can contain
-`IRegiserable` and other `IRegisterableContainer` components.
-
- >>> from zope.app.container.btree import BTreeContainer
- >>> from zope.app.component.registration import RegisterableContainer
-
- >>> class RegisterableManager(RegisterableContainer, BTreeContainer):
- ... pass
- >>> registerables = RegisterableManager()
-
-The `RegisterableContainer` class is merely a mixin and leaves it up to the
-developer to implement the `IContainer` interface. In our case, we simply used
-the default btree container implementation to provide the container
-interface. However, the `RegisterableContainer` class does implement the
-`IRegisterableContainer` interface, which means it ensures the existance of
-the `registrationManager` attribute, which always contains an
-`IRegistrationManager` instance:
-
- >>> registerables.registrationManager is not None
- True
- >>> interfaces.registration.IRegistrationManager.providedBy(
- ... registerables.registrationManager)
- True
-
-The registration manager is a simple container that can only contain
-components providing `IRegistration` and implements a method called
-`addRegistration(registration)` that lets you add a registration to the
-manager without specifying a name. The name will be automatically chosen for
-you and is returned. So let's add our two existing components and their
-registrations:
-
- >>> regManager = registerables.registrationManager
-
- >>> registerables['foo'] = foo
- >>> regManager.addRegistration(regFoo)
- 'Registration'
-
- >>> registerables['bar'] = bar
- >>> regManager.addRegistration(regBar)
- 'Registration2'
-
- >>> items = list(registerables.items())
- >>> items.sort()
- >>> items
- [(u'bar', <Component: 'Bar'>), (u'foo', <Component: 'Foo'>)]
- >>> regs = list(regManager.items())
- >>> regs.sort()
- >>> regs #doctest: +NORMALIZE_WHITESPACE
- [(u'Registration', <Registration for '<Component: 'Foo'>'>),
- (u'Registration2', <Registration for '<Component: 'Bar'>'>)]
-
-Of course, adding a registration to the registration manager does not mean the
-registration is added to the registry, since it still may not be active:
-
- >>> registry.getComponents()
- [<Component: 'Bar'>]
-
-Also, there are no restrictions on how many registrations you can create for a
-single component. For example, we can register the `foo` one more time:
-
- >>> regFoo2 = Registration(foo)
- >>> regManager.addRegistration(regFoo2)
- 'Registration3'
- >>> regs = list(regManager.items())
- >>> regs.sort()
- >>> regs #doctest: +NORMALIZE_WHITESPACE
- [(u'Registration', <Registration for '<Component: 'Foo'>'>),
- (u'Registration2', <Registration for '<Component: 'Bar'>'>),
- (u'Registration3', <Registration for '<Component: 'Foo'>'>)]
-
-This also means that our registry can provide a component multiple times:
-
- >>> regFoo.status = interfaces.registration.ActiveStatus
- >>> regFoo2.status = interfaces.registration.ActiveStatus
- >>> registry.getComponents()
- [<Component: 'Bar'>, <Component: 'Foo'>, <Component: 'Foo'>]
-
-Here is a UML diagram of the registerable container and registration manager
-and their relationships to the other registration-related components we
-discussed.
-
-::
-
- ----------------------------
- | IRegisterableContainer |
- | - - - - - - - - - - - - -|
- | 1 | 1 --------------------------
- | registrationManager ----+------| IRegistrationManager |
- | | --------------------------
- ---------------------------+ | *
- | * | * | 1 |
- | | | | 1
- | 1 +----+ -------------------
- ------------------- | IRegistration |
- | IRegisterable | -------------------
- ------------------- | *
- |
- --------------- 1 |
- | IRegistry |------+ if status == Active
- ---------------
-
-
-The Component Registration
---------------------------
-
-Until now we have only discussed the most primitive usage of the
-`ComponentRegistration`. Usually, a registry is not just interested in a
-component, but a set of methods which are specified by a particular
-interface. Thus the component registration supports the `interface`
-attribute. By default it is `None`:
-
- >>> regFoo.interface is None
- True
-
-We can now write another `IComponentRegistration` implementation that knows
-about the interface; in fact, it will pick the most specific one of the
-component:
-
- >>> from zope.interface import providedBy
- >>> class SomethingRegistration(Registration):
- ...
- ... def interface(self):
- ... return list(providedBy(self._component))[0]
- ... interface = property(interface)
-
-Next we create an interface and its implementation:
-
- >>> class ISomething(zope.interface.Interface):
- ... pass
-
- >>> class Something(Component):
- ... zope.interface.implements(ISomething)
-
-Creating a "something registration", we can see that the interface attribute
-is now available:
-
- >>> something = Something('Something')
- >>> reg = SomethingRegistration(something)
- >>> reg.interface
- <InterfaceClass __builtin__.ISomething>
-
-But hold on, we are not done yet! The component registration also supports a
-`permission` attribute. When set and an interface is available, the component
-will always be proxied using an interface checker for the specified
-permission. By default the permission is `None`:
-
- >>> reg.permission is None
- True
-
-Now we set a permission for the registration and the component should be
-proxies when returned:
-
- >>> from zope.security.checker import CheckerPublic
- >>> reg.permission = CheckerPublic
- >>> reg.component is something
- False
- >>> type(reg.component)
- <type 'zope.security._proxy._Proxy'>
-
-You can also, specify a permission in the constructor:
-
- >>> regNone = SomethingRegistration(None, 'zope.Public')
- >>> regNone.permission is CheckerPublic
- True
-
-If the interface is not available, the permission is ignored and the bare
-component is returned:
-
- >>> regSomething2 = Registration(something, 'zope.Public')
- >>> regSomething2.permission is CheckerPublic
- True
- >>> regSomething2.component is something
- True
-
-
-The `Registered` Adapter
-------------------------
-
-
-Registerable components are able to get a list of all their
-registrations. However, the adapter only works for components and
-registrations that are stored in the registerable container and registration
-manager, respectively.
-
- >>> from zope.app.component.registration import Registered
- >>> registered = Registered(foo)
- >>> registered.registrations() #doctest: +NORMALIZE_WHITESPACE
- [<Registration for '<Component: 'Foo'>'>,
- <Registration for '<Component: 'Foo'>'>]
-
Deleted: zope.app.component/trunk/src/zope/app/component/tests/deprecated35_statusproperty.txt
===================================================================
--- zope.app.component/trunk/src/zope/app/component/tests/deprecated35_statusproperty.txt 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/tests/deprecated35_statusproperty.txt 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,124 +0,0 @@
-============================
-Registration Status Property
-============================
-
-The registratio status property is a descriptor used to implement the
-`IRegistration`' interface's `status` property.
-
-The property accepts two possible values: `ActiveStatus` and
-`InactiveStatus`. When the registration is active, then the registration is
-also activated in the registry.
-
- >>> from zope.app.component.interfaces.registration import ActiveStatus
- >>> from zope.app.component.interfaces.registration import InactiveStatus
-
-When setting the `status` property to `ActiveStatus`, then the registration
-should be added to the nearest matching registry. Here, the registration's
-`getRegistry()` method is used to determine the registry. On the same token,
-if the value is set to `InactiveStatus` the registration should be removed
-from the registry.
-
-To demonstrate this functionality, we first have to create a stub registry
-
- >>> class Registry(object):
- ... registrations = []
- ... def register(self, registration):
- ... self.registrations.append(registration)
- ...
- ... def unregister(self, registration):
- ... del self.registrations[self.registrations.index(registration)]
- ...
- ... def registered(self, registration):
- ... return registration in self.registrations
-
- >>> registry = Registry()
-
-and a simple registration object
-
- >>> from zope.app.component.registration import RegistrationStatusProperty
- >>> class Registration(object):
- ... status = RegistrationStatusProperty()
- ...
- ... def __init__(self, registry):
- ... self.registry = registry
- ...
- ... def getRegistry(self):
- ... return self.registry
-
-Note that here only the `getRegistry()` is part of the registration API.
-
-Now that we have a registry and a registration class, let's create a
-registration:
-
- >>> reg = Registration(registry)
-
-At the beginning the registration is inactive:
-
- >>> reg.status
- u'Inactive'
- >>> reg.status is InactiveStatus
- True
- >>> reg in registry.registrations
- False
-
-Once we activate the registration, it appears in the registry:
-
- >>> reg.status = ActiveStatus
- >>> reg.status
- u'Active'
- >>> reg.status is ActiveStatus
- True
- >>> reg in registry.registrations
- True
-
-Now, once we deactivate the registration, it is not available in the registry
-anymore:
-
- >>> reg.status = InactiveStatus
- >>> reg.status
- u'Inactive'
- >>> reg.status is InactiveStatus
- True
- >>> reg in registry.registrations
- False
-
-
-Registration Events
--------------------
-
-When a registration is activated or deactivated, an
-`RegistrationActivatedEvent` or `RegistrationDeactivatedEvent` is created,
-respectively. Listening to these events can be useful for cases where you want
-to change the component based on registration status.
-
-To catch the events, we have to register a subscriber with the event
-framework:
-
- >>> events = []
- >>> def subscriber(event):
- ... global events
- ... events.append(event)
-
- >>> import zope.event
- >>> zope.event.subscribers.append(subscriber)
-
-Now we switch our registration to active:
-
- >>> reg.status = ActiveStatus
- >>> event = events.pop()
- >>> event.__class__
- <class 'zope.component.interfaces.Registered'>
- >>> event.object is reg
- True
-
-and deactivate it again:
-
- >>> reg.status = InactiveStatus
- >>> events.pop().__class__
- <class 'zope.component.interfaces.Unregistered'>
- >>> event.object is reg
- True
-
-Now make sure that we remove the subscriber again:
-
- >>> del zope.event.subscribers[zope.event.subscribers.index(subscriber)]
Deleted: zope.app.component/trunk/src/zope/app/component/tests/test_fields.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/tests/test_fields.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/tests/test_fields.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -1,30 +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.
-#
-##############################################################################
-"""Test fields.
-
-$Id$
-"""
-import unittest
-from zope.testing.doctestunit import DocTestSuite
-from zope.app.testing import placelesssetup
-
-def test_suite():
- return unittest.TestSuite((
- DocTestSuite('zope.app.component.back35',
- setUp=placelesssetup.setUp,
- tearDown=placelesssetup.tearDown),
- ))
-
-if __name__ == '__main__':
- unittest.main(defaultTest='test_suite')
Modified: zope.app.component/trunk/src/zope/app/component/tests/test_registration.py
===================================================================
--- zope.app.component/trunk/src/zope/app/component/tests/test_registration.py 2008-10-13 12:54:15 UTC (rev 92114)
+++ zope.app.component/trunk/src/zope/app/component/tests/test_registration.py 2008-10-13 13:18:24 UTC (rev 92115)
@@ -91,267 +91,6 @@
finally:
self._lock_release()
-
-def test_old_databases_backward_compat():
- """
-
-Let's open an old database and get the 3 site managers in it:
-
- >>> fs = oldfs()
- >>> demo = DemoStorage(base=fs)
- >>> db = DB(demo)
- >>> tm = transaction.TransactionManager()
- >>> root = db.open(transaction_manager=tm).root()
- >>> _ = tm.begin()
-
- >>> sm1 = root['Application'].getSiteManager()
- >>> [sm2] = sm1.subs
- >>> [sm3] = sm2.subs
-
-We can look up utilities as we expect:
-
- >>> sm1.getUtility(IFoo, '1') is sm1['default']['1']
- True
-
- >>> sm3.getUtility(IFoo, '3') is sm3['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '2') is sm2['default']['2']
- True
-
- >>> sm1.getUtility(IFoo, '2') is sm1['default']['2']
- True
-
- >>> sm1.getUtility(IFoo, '3') is sm1['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '3') is sm2['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '4') is sm2['default']['4']
- True
-
- >>> sm3.getUtility(IFoo, '4') is sm3['default']['4']
- True
-
- >>> sm3.getUtility(IFoo, '5') is sm3['default']['5']
- True
-
-and we get registration info:
-
- >>> sorted([r.name for r in sm2.registeredUtilities()])
- [u'2', u'3', u'4']
-
-We don't have any adapter or subscriber information, because it wasn't
-previously supported to register those:
-
- >>> len(list(sm2.registeredAdapters()))
- 0
- >>> len(list(sm2.registeredSubscriptionAdapters()))
- 0
- >>> len(list(sm2.registeredHandlers()))
- 0
-
-We haven't modified anything yet. We can see this in a number of
-ways. If we look at the internal data structured used, we can see
-that they are weird:
-
- >>> sm2._utility_registrations.__class__.__name__
- '_OldUtilityRegistrations'
-
- >>> sm2._adapter_registrations.__class__.__name__
- '_OldAdapterRegistrations'
-
- >>> sm2._subscription_registrations.__class__.__name__
- '_OldSubscriberRegistrations'
-
- >>> sm2._handler_registrations.__class__.__name__
- '_OldSubscriberRegistrations'
-
-and the registries have a _registrations attribute, which is a sign
-that they haven't been converted yet:
-
- >>> hasattr(sm2.utilities, '_registrations')
- True
-
- >>> hasattr(sm2.adapters, '_registrations')
- True
-
-We'll commit the transaction and make sure the database hasn't
-grown. (This relies on a buglet in DemoStorage length computation.)
-
- >>> tm.commit()
- >>> len(demo) == len(fs)
- True
-
-Of course, we can register new utilities:
-
- >>> _ = tm.begin()
- >>> sm1.registerUtility(Foo('one'), IFoo, '1')
- >>> sm2.registerUtility(Foo('two'), IFoo, '2')
- >>> tm.commit()
-
-We should then be able to look up the newly registered utilities.
-Let's try to do so in a separate connection:
-
- >>> tm2 = transaction.TransactionManager()
- >>> root2 = db.open(transaction_manager=tm2).root()
- >>> _ = tm2.begin()
-
- >>> sm1 = root2['Application'].getSiteManager()
- >>> [sm2] = sm1.subs
- >>> [sm3] = sm2.subs
-
- >>> sm1.getUtility(IFoo, '1').name
- 'one'
-
- >>> sm2.getUtility(IFoo, '2').name
- 'two'
-
- >>> sm1.getUtility(IFoo, '2') is sm1['default']['2']
- True
-
- >>> sm1.getUtility(IFoo, '3') is sm1['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '3') is sm2['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '4') is sm2['default']['4']
- True
-
- >>> sm3.getUtility(IFoo, '4') is sm3['default']['4']
- True
-
- >>> sm3.getUtility(IFoo, '5') is sm3['default']['5']
- True
-
- >>> sorted([r.name for r in sm2.registeredUtilities()])
- [u'2', u'3', u'4']
-
-
-Because we registered utilities, the corresponding data structures
-have been updated:
-
- >>> sm2._utility_registrations.__class__.__name__
- 'PersistentMapping'
-
- >>> hasattr(sm2.utilities, '_registrations')
- False
-
-But other data structures haven't been effected:
-
- >>> sm2._adapter_registrations.__class__.__name__
- '_OldAdapterRegistrations'
-
- >>> hasattr(sm2.adapters, '_registrations')
- True
-
-Nor, of course, have the data structures for sites that we haven't
-changed:
-
- >>> sm3._utility_registrations.__class__.__name__
- '_OldUtilityRegistrations'
-
- >>> hasattr(sm3.utilities, '_registrations')
- True
-
-The _evolve_to_generation_4 method actually converts the remaining
-data structures. It also evolves all of it's subsites:
-
- >>> sm1._evolve_to_generation_4()
- >>> tm2.commit()
-
-and we see that all of the data structures have been converted:
-
- >>> sm1._utility_registrations.__class__.__name__
- 'PersistentMapping'
- >>> sm1._adapter_registrations.__class__.__name__
- 'PersistentMapping'
- >>> sm1._subscription_registrations.__class__.__name__
- 'PersistentList'
- >>> sm1._handler_registrations.__class__.__name__
- 'PersistentList'
- >>> hasattr(sm1.utilities, '_registrations')
- False
- >>> hasattr(sm1.adapters, '_registrations')
- False
-
- >>> sm2._utility_registrations.__class__.__name__
- 'PersistentMapping'
- >>> sm2._adapter_registrations.__class__.__name__
- 'PersistentMapping'
- >>> sm2._subscription_registrations.__class__.__name__
- 'PersistentList'
- >>> sm2._handler_registrations.__class__.__name__
- 'PersistentList'
- >>> hasattr(sm2.utilities, '_registrations')
- False
- >>> hasattr(sm2.adapters, '_registrations')
- False
-
- >>> sm3._utility_registrations.__class__.__name__
- 'PersistentMapping'
- >>> sm3._adapter_registrations.__class__.__name__
- 'PersistentMapping'
- >>> sm3._subscription_registrations.__class__.__name__
- 'PersistentList'
- >>> sm3._handler_registrations.__class__.__name__
- 'PersistentList'
- >>> hasattr(sm3.utilities, '_registrations')
- False
- >>> hasattr(sm3.adapters, '_registrations')
- False
-
-and that lookups still work as expected:
-
-
- >>> sm1.getUtility(IFoo, '1').name
- 'one'
-
- >>> sm2.getUtility(IFoo, '2').name
- 'two'
-
- >>> sm1.getUtility(IFoo, '2') is sm1['default']['2']
- True
-
- >>> sm1.getUtility(IFoo, '3') is sm1['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '3') is sm2['default']['3']
- True
-
- >>> sm2.getUtility(IFoo, '4') is sm2['default']['4']
- True
-
- >>> sm3.getUtility(IFoo, '4') is sm3['default']['4']
- True
-
- >>> sm3.getUtility(IFoo, '5') is sm3['default']['5']
- True
-
-getAllUtilitiesRegisteredFor should work too: :)
-
- >>> all = list(sm3.getAllUtilitiesRegisteredFor(IFoo))
- >>> all.remove(sm1['default']['1'])
- >>> all.remove(sm1['default']['2'])
- >>> all.remove(sm1['default']['3'])
- >>> all.remove(sm2['default']['2'])
- >>> all.remove(sm2['default']['3'])
- >>> all.remove(sm2['default']['4'])
- >>> all.remove(sm3['default']['3'])
- >>> all.remove(sm3['default']['4'])
- >>> all.remove(sm3['default']['5'])
- >>> len(all)
- 2
-
-Cleanup:
-
- >>> db.close()
-
-"""
-
-
class GlobalRegistry:
pass
@@ -496,9 +235,6 @@
def test_suite():
suite = unittest.TestSuite((
- doctest.DocFileSuite('deprecated35_statusproperty.txt',
- 'deprecated35_registration.txt',
- setUp=setUpOld, tearDown=tearDown),
doctest.DocTestSuite(setUp=setUp, tearDown=tearDown)
))
return suite
More information about the Checkins
mailing list