diff options
| author | Dan Korostelev <nadako@gmail.com> | 2009-03-02 16:01:59 +0000 |
|---|---|---|
| committer | Dan Korostelev <nadako@gmail.com> | 2009-03-02 16:01:59 +0000 |
| commit | bba63ea04167827e91c74b5a6d059655a3b4542b (patch) | |
| tree | e0fa173bab8cbababf96c0d25b480b4eb6b31941 /src | |
| parent | 7659c4e3ec54d2d14237a4c971cef2e78106baac (diff) | |
| download | zope-component-bba63ea04167827e91c74b5a6d059655a3b4542b.tar.gz | |
Remove deprecated stuff. Remove duplicated adapter declaration code. Clean up documentation a bit.
Diffstat (limited to 'src')
| -rw-r--r-- | src/zope/component/DEPENDENCIES.cfg | 5 | ||||
| -rw-r--r-- | src/zope/component/README.txt | 4 | ||||
| -rw-r--r-- | src/zope/component/__init__.py | 26 | ||||
| -rw-r--r-- | src/zope/component/_api.py | 43 | ||||
| -rw-r--r-- | src/zope/component/_declaration.py | 31 | ||||
| -rw-r--r-- | src/zope/component/adapter.py | 169 | ||||
| -rw-r--r-- | src/zope/component/back35.py | 20 | ||||
| -rw-r--r-- | src/zope/component/bbb/interfaces.py | 248 | ||||
| -rw-r--r-- | src/zope/component/contextdependent.py | 32 | ||||
| -rw-r--r-- | src/zope/component/exceptions.py | 30 | ||||
| -rw-r--r-- | src/zope/component/factory.py | 2 | ||||
| -rw-r--r-- | src/zope/component/factory.txt | 15 | ||||
| -rw-r--r-- | src/zope/component/globalregistry.py | 88 | ||||
| -rw-r--r-- | src/zope/component/interfaces.py | 9 | ||||
| -rw-r--r-- | src/zope/component/persistentregistry.py | 2 | ||||
| -rw-r--r-- | src/zope/component/persistentregistry.txt | 2 | ||||
| -rw-r--r-- | src/zope/component/registry.py | 26 | ||||
| -rw-r--r-- | src/zope/component/service.py | 178 | ||||
| -rw-r--r-- | src/zope/component/servicenames.py | 24 | ||||
| -rw-r--r-- | src/zope/component/site.py | 39 | ||||
| -rw-r--r-- | src/zope/component/socketexample.txt | 13 | ||||
| -rw-r--r-- | src/zope/component/utility.py | 76 |
22 files changed, 29 insertions, 1053 deletions
diff --git a/src/zope/component/DEPENDENCIES.cfg b/src/zope/component/DEPENDENCIES.cfg deleted file mode 100644 index 9880196..0000000 --- a/src/zope/component/DEPENDENCIES.cfg +++ /dev/null @@ -1,5 +0,0 @@ -zope.exceptions -zope.interface -zope.testing -zope.deprecation -zope.deferredimport diff --git a/src/zope/component/README.txt b/src/zope/component/README.txt index 0c10dfb..8837beb 100644 --- a/src/zope/component/README.txt +++ b/src/zope/component/README.txt @@ -236,7 +236,7 @@ one: True Subscription Adapters -********************* +--------------------- Unlike regular adapters, subscription adapters are used when we want all of the adapters that adapt an object to a particular adapter. @@ -323,7 +323,7 @@ We can then use the subscribers to validate objects: ['too short'] Handlers -******** +-------- Handlers are subscription adapter factories that don't produce anything. They do all of their work when called. Handlers diff --git a/src/zope/component/__init__.py b/src/zope/component/__init__.py index 8f8acdc..c9259ef 100644 --- a/src/zope/component/__init__.py +++ b/src/zope/component/__init__.py @@ -15,9 +15,7 @@ $Id$ """ -import sys import zope.deferredimport -import zope.interface from zope.interface import moduleProvides, Interface from zope.interface import providedBy, implementedBy from zope.component.interfaces import IComponentArchitecture @@ -49,29 +47,5 @@ zope.deferredimport.defineFrom( 'adapter', 'adapts', 'adaptedBy', ) -zope.deferredimport.deprecated( - "Use IComponentLookup instead. ISiteManager will be removed in Zope 3.5.", - ISiteManager = "zope.component.interfaces:IComponentLookup", - ) - moduleProvides(IComponentArchitecture, IComponentRegistrationConvenience) __all__ = tuple(IComponentArchitecture) - -zope.deferredimport.deprecated( - "This object was deprecated long ago. Only import is allowed now " - "and will be disallows in Zope 3.5.", - getGlobalServices = "zope.component.back35:deprecated", - getGlobalService = "zope.component.back35:deprecated", - getService = "zope.component.back35:deprecated", - getServiceDefinitions = "zope.component.back35:deprecated", - getView = "zope.component.back35:deprecated", - queryView = "zope.component.back35:deprecated", - getMultiView = "zope.component.back35:deprecated", - queryMultiView = "zope.component.back35:deprecated", - getViewProviding = "zope.component.back35:deprecated", - queryViewProviding = "zope.component.back35:deprecated", - getDefaultViewName = "zope.component.back35:deprecated", - queryDefaultViewName = "zope.component.back35:deprecated", - getResource = "zope.component.back35:deprecated", - queryResource = "zope.component.back35:deprecated", - ) diff --git a/src/zope/component/_api.py b/src/zope/component/_api.py index 12ff49d..52a3542 100644 --- a/src/zope/component/_api.py +++ b/src/zope/component/_api.py @@ -26,6 +26,7 @@ from zope.component.interfaces import IFactory from zope.component.interfaces import ComponentLookupError from zope.component.interfaces import IComponentLookup from zope.component.globalregistry import base +from zope.component._declaration import adapter, adapts, adaptedBy # Try to be hookable. Do so in a try/except to avoid a hard dependency. try: @@ -136,48 +137,6 @@ def handle(*objects): for ignored in sitemanager.subscribers(objects, None): pass -class _adapts_descr(object): - def __init__(self, interfaces): - self.interfaces = interfaces - - def __get__(self, inst, cls): - if inst is None: - return self.interfaces - raise AttributeError('__component_adapts__') - -_class_types = type, types.ClassType -class adapter: - - def __init__(self, *interfaces): - self.interfaces = interfaces - - def __call__(self, ob): - if isinstance(ob, _class_types): - ob.__component_adapts__ = _adapts_descr(self.interfaces) - else: - ob.__component_adapts__ = self.interfaces - - return ob - -def adapts(*interfaces): - frame = sys._getframe(1) - locals = frame.f_locals - - # Try to make sure we were called from a class def. In 2.2.0 we can't - # check for __module__ since it doesn't seem to be added to the locals - # until later on. - if (locals is frame.f_globals) or ( - ('__module__' not in locals) and sys.version_info[:3] > (2, 2, 0)): - raise TypeError("adapts can be used only from a class definition.") - - if '__component_adapts__' in locals: - raise TypeError("adapts can be used only once in a class definition.") - - locals['__component_adapts__'] = _adapts_descr(interfaces) - -def adaptedBy(ob): - return getattr(ob, '__component_adapts__', None) - ############################################################################# # Register the component architectures adapter hook, with the adapter hook # registry of the `zope.inteface` package. This way we will be able to call diff --git a/src/zope/component/_declaration.py b/src/zope/component/_declaration.py index 2d6706a..df85de7 100644 --- a/src/zope/component/_declaration.py +++ b/src/zope/component/_declaration.py @@ -11,31 +11,13 @@ # FOR A PARTICULAR PURPOSE. # ############################################################################## -"""Zope 3 Component Architecture +"""Adapter declarations $Id$ """ import types import sys -from zope.interface import Interface -from zope.interface import providedBy, implementedBy -from zope.component.interfaces import IComponentArchitecture -from zope.component.interfaces import IComponentRegistrationConvenience -from zope.component.interfaces import IDefaultViewName -from zope.component.interfaces import IFactory -from zope.component.interfaces import ComponentLookupError -from zope.component.interfaces import IComponentLookup -class _adapts_descr(object): - def __init__(self, interfaces): - self.interfaces = interfaces - - def __get__(self, inst, cls): - if inst is None: - return self.interfaces - raise AttributeError('__component_adapts__') - -_class_types = type, types.ClassType class adapter: def __init__(self, *interfaces): @@ -67,3 +49,14 @@ def adapts(*interfaces): def adaptedBy(ob): return getattr(ob, '__component_adapts__', None) + +_class_types = type, types.ClassType + +class _adapts_descr(object): + def __init__(self, interfaces): + self.interfaces = interfaces + + def __get__(self, inst, cls): + if inst is None: + return self.interfaces + raise AttributeError('__component_adapts__') diff --git a/src/zope/component/adapter.py b/src/zope/component/adapter.py deleted file mode 100644 index 2cbd1ad..0000000 --- a/src/zope/component/adapter.py +++ /dev/null @@ -1,169 +0,0 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## - - -import warnings - -warnings.warn("This module is deprecated and will go away in Zope 3.5. ", - DeprecationWarning, 2) - - -import sys -import warnings -from types import ClassType - -from zope.component.interfaces import IRegistry, ComponentLookupError -from zope.component.bbb.interfaces import IAdapterService -from zope.component.bbb.service import GlobalService -from zope.component.registry import AdapterRegistration, SubscriptionRegistration -from zope.interface import implements, providedBy, Interface, implementedBy -from zope.interface.interfaces import IInterface - -class IGlobalAdapterService(IAdapterService, IRegistry): - - def register(required, provided, name, factory, info=''): - """Register an adapter factory - - :Parameters: - - `required`: a sequence of specifications for objects to be - adapted. - - `provided`: The interface provided by the adapter - - `name`: The adapter name - - `factory`: The object used to compute the adapter - - `info`: Provide some info about this particular adapter. - """ - - def subscribe(required, provided, factory, info=''): - """Register a subscriber factory - - :Parameters: - - `required`: a sequence of specifications for objects to be - adapted. - - `provided`: The interface provided by the adapter - - `name`: The adapter name - - `factory`: The object used to compute the subscriber - - `info`: Provide some info about this particular adapter. - """ - -class AdapterService(object): - """Base implementation of an adapter service, implementing only the - `IAdapterService` interface. - - No write-methods were implemented. - """ - - implements(IAdapterService) - - def __init__(self, sitemanager=None): - if sitemanager is None: - from zope.component.globalregistry import BaseGlobalComponents - sitemanager = BaseGlobalComponents() - self.sm = sitemanager - - def __getattr__(self, name): - attr = getattr(self.sm.adapters, name) - if attr is not None: - return attr - raise AttributeError(name) - - -class GlobalAdapterService(AdapterService, GlobalService): - """Global Adapter Service implementation.""" - - implements(IGlobalAdapterService) - - def __init__(self, sitemanager=None): - super(GlobalAdapterService, self).__init__(sitemanager) - - def register(self, required, provided, name, factory, info=''): - """Register an adapter - - >>> registry = GlobalAdapterService() - >>> class R1(Interface): - ... pass - >>> class R2(R1): - ... pass - >>> class P1(Interface): - ... pass - >>> class P2(P1): - ... pass - - >>> registry.register((R1, ), P2, 'bob', 'c1', 'd1') - >>> registry.register((R1, ), P2, '', 'c2', 'd2') - >>> registry.lookup((R2, ), P1, '') - 'c2' - - >>> registrations = map(repr, registry.registrations()) - >>> registrations.sort() - >>> for registration in registrations: - ... print registration - AdapterRegistration(('R1',), 'P2', '', 'c2', 'd2') - AdapterRegistration(('R1',), 'P2', 'bob', 'c1', 'd1') - - Let's make sure that we can also register regular classes for - adaptation. - - >>> class O1(object): - ... pass - >>> class O2(object): - ... pass - >>> class O3(object): - ... def __init__(self, obj1, obj2=None): - ... pass - - >>> registry.register((O1, ), R1, '', O3) - >>> registry.queryAdapter(O1(), R1, '').__class__ - <class 'zope.component.bbb.adapter.O3'> - - >>> registry.register((O1, O2), R1, '', O3) - >>> registry.queryMultiAdapter((O1(), O2()), R1, '').__class__ - <class 'zope.component.bbb.adapter.O3'> - """ - self.sm.provideAdapter(required, provided, name, factory, info) - - def subscribe(self, required, provided, factory, info=''): - """Register an subscriptions adapter - - >>> registry = GlobalAdapterService() - >>> class R1(Interface): - ... pass - >>> class R2(R1): - ... pass - >>> class P1(Interface): - ... pass - >>> class P2(P1): - ... pass - - >>> registry.subscribe((R1, ), P2, 'c1', 'd1') - >>> registry.subscribe((R1, ), P2, 'c2', 'd2') - >>> subscriptions = map(str, registry.subscriptions((R2, ), P1)) - >>> subscriptions.sort() - >>> subscriptions - ['c1', 'c2'] - - >>> registrations = map(repr, registry.registrations()) - >>> registrations.sort() - >>> for registration in registrations: - ... print registration - SubscriptionRegistration(('R1',), 'P2', 'c1', 'd1') - SubscriptionRegistration(('R1',), 'P2', 'c2', 'd2') - - """ - self.sm.subscribe(required, provided, factory, info) - - def registrations(self): - for registration in self.sm.registrations(): - if isinstance(registration, - (AdapterRegistration, SubscriptionRegistration)): - yield registration diff --git a/src/zope/component/back35.py b/src/zope/component/back35.py deleted file mode 100644 index 1c91d77..0000000 --- a/src/zope/component/back35.py +++ /dev/null @@ -1,20 +0,0 @@ -############################################################################## -# -# Copyright (c) 2005 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. -# -############################################################################## -"""Things to be deprecated. - -$Id$ -""" - -def deprecated(*args, **kw): - raise NotImplementedError("This function is no-longer implemented") diff --git a/src/zope/component/bbb/interfaces.py b/src/zope/component/bbb/interfaces.py index 6ae05c3..2f8597e 100644 --- a/src/zope/component/bbb/interfaces.py +++ b/src/zope/component/bbb/interfaces.py @@ -19,254 +19,6 @@ __docformat__ = "reStructuredText" from zope.interface import Interface, Attribute - -class IBBBComponentArchitecture(Interface): - """The Component Architecture is defined by six key services, - all of which are managed by service managers. - """ - - # basic service manager tools - - def getGlobalServices(): - """Get the global service manager.""" - - def getGlobalService(name): - """Get a global service.""" - - def getServices(context=None): - """Get the service manager - - If context is None, an application-defined policy is used to choose - an appropriate service manager. - - If 'context' is not None, context is adapted to IServiceService, and - this adapter is returned. - """ - - def getService(name, context=None): - """Get a named service. - - Returns the service defined by 'name' from the service manager. - - If context is None, an application-defined policy is used to choose - an appropriate service manager. - - If 'context' is not None, context is adapted to IServiceService, and - this adapter is returned. - """ - - def getServiceDefinitions(context=None): - """Get service definitions - - Returns a dictionary of the service definitions from the service - manager in the format {nameString: serviceInterface}. - - The default behavior of placeful service managers is to include - service definitions above them, but this can be overridden. - - If context is None, an application-defined policy is used to choose - an appropriate service manager. - - If 'context' is not None, context is adapted to IServiceService, and - this adapter is returned. - """ - - # Presentation service - - def getView(object, name, request, providing=Interface, context=None): - """Get a named view for a given object. - - The request must implement IPresentationRequest: it provides - the view type and the skin name. The nearest one to the - object is found. If a matching view cannot be found, raises - ComponentLookupError. - """ - - def queryView(object, name, request, - default=None, providing=Interface, context=None): - """Look for a named view for a given object. - - The request must implement IPresentationRequest: it provides - the view type and the skin name. The nearest one to the - object is found. If a matching view cannot be found, returns - default. - - If context is not specified, attempts to use object to specify - a context. - """ - - def getMultiView(objects, request, providing=Interface, name='', - context=None): - """Look for a multi-view for given objects - - The request must implement IPresentationRequest: it provides - the view type and the skin name. The nearest one to the - object is found. If a matching view cannot be found, raises - ComponentLookupError. - - If context is not specified, attempts to use the first object - to specify a context. - """ - - def queryMultiView(objects, request, providing=Interface, name='', - default=None, context=None): - """Look for a multi-view for given objects - - The request must implement IPresentationRequest: it provides - the view type and the skin name. The nearest one to the - object is found. If a matching view cannot be found, returns - default. - - If context is not specified, attempts to use the first object - to specify a context. - """ - - def getViewProviding(object, providing, request, context=None): - """Look for a view based on the interface it provides. - - A call to this method is equivalent to: - - getView(object, '', request, context, providing) - """ - - def queryViewProviding(object, providing, request, - default=None, context=None): - """Look for a view that provides the specified interface. - - A call to this method is equivalent to: - - queryView(object, '', request, default, context, providing) - """ - - def getDefaultViewName(object, request, context=None): - """Get the name of the default view for the object and request. - - The request must implement IPresentationRequest, and provides the - desired view type. The nearest one to the object is found. - If a matching default view name cannot be found, raises - ComponentLookupError. - - If context is not specified, attempts to use - object to specify a context. - """ - - def queryDefaultViewName(object, request, default=None, context=None): - """Look for the name of the default view for the object and request. - - The request must implement IPresentationRequest, and provides - the desired view type. The nearest one to the object is - found. If a matching default view name cannot be found, - returns the default. - - If context is not specified, attempts to use object to specify - a context. - """ - - def getResource(name, request, providing=Interface, context=None): - """Get a named resource for a given request - - The request must implement IPresentationRequest. - - The context provides a place to look for placeful resources. - - A ComponentLookupError will be raised if the component can't - be found. - """ - - def queryResource(name, request, default=None, providing=Interface, - context=None): - """Get a named resource for a given request - - The request must implement IPresentationRequest. - - The context provides a place to look for placeful resources. - - If the component can't be found, the default is returned. - """ - - -class IServiceService(Interface): - """A service to manage Services.""" - - def getServiceDefinitions(): - """Retrieve all Service Definitions - - Should return a list of tuples (name, interface) - """ - - def getInterfaceFor(name): - """Retrieve the service interface for the given name - """ - - def getService(name): - """Retrieve a service implementation - - Raises ComponentLookupError if the service can't be found. - """ - - -class IUtilityService(Interface): - """A service to manage Utilities.""" - - def getUtility(interface, name=''): - """Look up a utility that provides an interface. - - If one is not found, raises ComponentLookupError. - """ - - def queryUtility(interface, name='', default=None): - """Look up a utility that provides an interface. - - If one is not found, returns default. - """ - - def getUtilitiesFor(interface): - """Look up the registered utilities that provide an interface. - - Returns an iterable of name-utility pairs. - """ - - def getAllUtilitiesRegisteredFor(interface): - """Return all registered utilities for an interface - - This includes overwridden utilities. - - An iterable of utility instances is returned. No names are - returned. - """ - -class IAdapterService(Interface): - """A service to manage Adapters.""" - - def queryAdapter(object, interface, name, default=None): - """Look for a named adapter to an interface for an object - - If a matching adapter cannot be found, returns the default. - - The name consisting of an empty string is reserved for unnamed - adapters. The unnamed adapter methods will often call the - named adapter methods with an empty string for a name. - """ - - def queryMultiAdapter(objects, interface, name, default=None): - """Look for a multi-adapter to an interface for an object - - If a matching adapter cannot be found, returns the default. - - The name consisting of an empty string is reserved for unnamed - adapters. The unnamed adapter methods will often call the - named adapter methods with an empty string for a name. - """ - - def subscribers(required, provided): - """Get subscribers - - Subscribers are returned that provide the provided interface - and that depend on and are comuted from the sequence of - required objects. - """ - - class IContextDependent(Interface): """Components implementing this interface must have a context component. diff --git a/src/zope/component/contextdependent.py b/src/zope/component/contextdependent.py deleted file mode 100644 index 279e3f6..0000000 --- a/src/zope/component/contextdependent.py +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -""" -$Id$ -""" - -import warnings - -warnings.warn("This module is deprecated and will go away in Zope 3.5.", - DeprecationWarning, 2) - -from zope.component.interfaces import IContextDependent -from zope.interface import implements - -class ContextDependent(object): - """standard boilerplate for context dependent objects""" - - implements(IContextDependent) - - def __init__(self, context): - self.context = context diff --git a/src/zope/component/exceptions.py b/src/zope/component/exceptions.py deleted file mode 100644 index d8b295b..0000000 --- a/src/zope/component/exceptions.py +++ /dev/null @@ -1,30 +0,0 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -""" -$Id$ -""" - -import warnings - -warnings.warn("This module is deprecated and will go away in Zope 3.5. " - "Use zope.component.interfaces instead.", - DeprecationWarning, 2) - -from zope.component.interfaces import ComponentLookupError -from zope.component.interfaces import Invalid, Misused - - -__all__ = ["ComponentLookupError", - "Invalid", - "Misused"] diff --git a/src/zope/component/factory.py b/src/zope/component/factory.py index dc75c6b..2360493 100644 --- a/src/zope/component/factory.py +++ b/src/zope/component/factory.py @@ -44,4 +44,4 @@ class Factory(object): return implementedBy(self._callable) def __repr__(self): - return '<%s for %s>' %(self.__class__.__name__, `self._callable`) + return '<%s for %s>' % (self.__class__.__name__, repr(self._callable)) diff --git a/src/zope/component/factory.txt b/src/zope/component/factory.txt index b2ec25c..1067fef 100644 --- a/src/zope/component/factory.txt +++ b/src/zope/component/factory.txt @@ -1,4 +1,3 @@ -========= Factories ========= @@ -27,7 +26,7 @@ The Factory Class >>> factory3 = Factory(lambda x: x, 'Func', 'Function', (IFunction,)) Calling a Factory -+++++++++++++++++ +~~~~~~~~~~~~~~~~~ Here we test whether the factory correctly creates the objects and including the correct handling of constructor elements. @@ -59,7 +58,7 @@ Since we passed in a couple positional and keyword arguments Title and Description -+++++++++++++++++++++ +~~~~~~~~~~~~~~~~~~~~~ >>> factory.title 'Klass' @@ -76,7 +75,7 @@ Title and Description Provided Interfaces -+++++++++++++++++++ +~~~~~~~~~~~~~~~~~~~ >>> implemented = factory.getInterfaces() >>> implemented.isOrExtends(IKlass) @@ -93,7 +92,7 @@ Provided Interfaces [<InterfaceClass __builtin__.IFunction>] -The Componant Architecture Factory API +The Component Architecture Factory API -------------------------------------- >>> import zope.component @@ -104,7 +103,7 @@ The Componant Architecture Factory API >>> gsm.registerUtility(factory, IFactory, 'klass') Creating an Object -++++++++++++++++++ +~~~~~~~~~~~~~~~~~~ >>> kl = zope.component.createObject('klass', 1, 2, foo=3, bar=4) >>> isinstance(kl, Klass) @@ -115,7 +114,7 @@ Creating an Object {'foo': 3, 'bar': 4} Accessing Provided Interfaces -+++++++++++++++++++++++++++++ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>> implemented = zope.component.getFactoryInterfaces('klass') >>> implemented.isOrExtends(IKlass) @@ -124,7 +123,7 @@ Accessing Provided Interfaces [<InterfaceClass __builtin__.IKlass>] List of All Factories -+++++++++++++++++++++ +~~~~~~~~~~~~~~~~~~~~~ >>> [(name, fac.__class__) for name, fac in ... zope.component.getFactoriesFor(IKlass)] diff --git a/src/zope/component/globalregistry.py b/src/zope/component/globalregistry.py index d1c8423..bb8a98b 100644 --- a/src/zope/component/globalregistry.py +++ b/src/zope/component/globalregistry.py @@ -17,7 +17,6 @@ $Id$ """ from zope.interface import implements from zope.interface.adapter import AdapterRegistry -from zope.deprecation.deprecation import deprecate from zope.component.registry import Components from zope.component.interfaces import Invalid, IComponentLookup, IRegistry from zope.component.interfaces import ComponentLookupError @@ -39,50 +38,7 @@ class GlobalAdapterRegistry(AdapterRegistry): def __reduce__(self): return GAR, (self.__parent__, self.__name__) -######################################################################## -# -# BBB 2006/02/28 -- to be removed after 12 months - -class _IGlobalSiteManager(IComponentLookup, IRegistry): - - def provideAdapter(required, provided, name, factory, info=''): - """Register an adapter factory - - :Parameters: - - `required`: a sequence of specifications for objects to be - adapted. - - `provided`: The interface provided by the adapter - - `name`: The adapter name - - `factory`: The object used to compute the adapter - - `info`: Provide some info about this particular adapter. - """ - - def subscribe(required, provided, factory, info=''): - """Register a subscriber factory - - :Parameters: - - `required`: a sequence of specifications for objects to be - adapted. - - `provided`: The interface provided by the adapter - - `name`: The adapter name - - `factory`: The object used to compute the subscriber - - `info`: Provide some info about this particular adapter. - """ - - def provideUtility(providedInterface, component, name='', info='', - strict=True): - """Register a utility - - If strict is true, then the specified component *must* implement the - `providedInterface`. Turning strict off is particularly useful for - tests.""" - -# -######################################################################## - - class BaseGlobalComponents(Components): - implements(_IGlobalSiteManager) def _init_registries(self): self.adapters = GlobalAdapterRegistry(self, 'adapters') @@ -92,50 +48,6 @@ class BaseGlobalComponents(Components): # Global site managers are pickled as global objects return self.__name__ - #################################################################### - # - # BBB 2006/02/28 -- to be removed after 12 months - - @deprecate("The provideAdapter method of the global site manager has been " - "deprecated. Use registerAdapter instead.") - def provideAdapter(self, required, provided, name, factory, info=''): - self.registerAdapter(factory, required, provided, name, info) - - @deprecate("The subscribe method of the global site manager has been " - "deprecated. Use registerHandler or registerSubscriptionAdapter " - "instead.") - def subscribe(self, required, provided, factory, info=''): - if provided is None: - self.registerHandler(factory, required, u'', info) - else: - self.registerSubscriptionAdapter(factory, required, provided, - info=info) - - @deprecate("The provideUtility method of the global site manager has been " - "deprecated. Use registerUtility instead.") - def provideUtility(self, providedInterface, component, name='', info='', - strict=True): - if strict and not providedInterface.providedBy(component): - raise Invalid("The registered component doesn't provide " - "the promised interface.") - - self.registerUtility(component, providedInterface, name, info) - - @deprecate("The registrations method of the global site manager has been " - "deprecate. Use either registeredAdapters, registeredUtilities, " - "or registeredSubscriptionAdapters instead.") - def registrations(self): - for reg in self.registeredAdapters(): - yield reg - for reg in self.registeredSubscriptionAdapters(): - yield reg - for reg in self.registeredHandlers(): - yield reg - for reg in self.registeredUtilities(): - yield reg - # - #################################################################### - base = BaseGlobalComponents('base') try: diff --git a/src/zope/component/interfaces.py b/src/zope/component/interfaces.py index 56c0063..4d36c74 100644 --- a/src/zope/component/interfaces.py +++ b/src/zope/component/interfaces.py @@ -45,10 +45,6 @@ class IObjectEvent(interface.Interface): class ObjectEvent(object): interface.implements(IObjectEvent) - # for repr backward compatibility. In the next release cycle, we'll - # provide a testing framework that addresses repr migration. - __module__ = 'zope.app.event.objectevent' - def __init__(self, object): self.object = object @@ -379,11 +375,6 @@ class IComponentLookup(interface.Interface): returned. """ -zope.deferredimport.deprecated( - "Use IComponentLookup instead. ISiteManager will be removed in 2007.", - ISiteManager = "zope.component.interfaces:IComponentLookup", - ) - class IComponentRegistrationConvenience(interface.Interface): """API for registering components. diff --git a/src/zope/component/persistentregistry.py b/src/zope/component/persistentregistry.py index 2c8a15d..475d3cb 100644 --- a/src/zope/component/persistentregistry.py +++ b/src/zope/component/persistentregistry.py @@ -54,5 +54,3 @@ class PersistentComponents(zope.component.registry.Components): self._adapter_registrations = persistent.mapping.PersistentMapping() self._subscription_registrations = persistent.list.PersistentList() self._handler_registrations = persistent.list.PersistentList() - - diff --git a/src/zope/component/persistentregistry.txt b/src/zope/component/persistentregistry.txt index 09157c2..bf0de9e 100644 --- a/src/zope/component/persistentregistry.txt +++ b/src/zope/component/persistentregistry.txt @@ -3,4 +3,4 @@ Persistent Component Management Persistent component management allows persistent management of components. From a usage point of view, there shouldn't be any new -behavior beyond what's described in components.txt. +behavior beyond what's described in registry.txt. diff --git a/src/zope/component/registry.py b/src/zope/component/registry.py index f94aa2b..7ed7458 100644 --- a/src/zope/component/registry.py +++ b/src/zope/component/registry.py @@ -17,7 +17,6 @@ $Id$ """ import types -import zope.deprecation import zope.interface.adapter from zope import component, interface from zope.component import interfaces @@ -446,29 +445,6 @@ class AdapterRegistration(object): def __cmp__(self, other): return cmp(self.__repr__(), other.__repr__()) - # this may actually not be needed as component did not exist as - # an attribute in Zope 3.2, but we'll leave it in to be sure. - @property - @zope.deprecation.deprecate( - "The component attribute on adapter registrations will be unsupported " - "in Zope 3.5. Use the factory attribute instead.") - def component(self): - return self.factory - - @property - @zope.deprecation.deprecate( - "The value attribute on adapter registrations will be unsupported " - "in Zope 3.5. Use the factory attribute instead.") - def value(self): - return self.factory - - @property - @zope.deprecation.deprecate( - "The doc attribute on adapter registrations will be unsupported " - "in Zope 3.5. Use the info attribute instead.") - def doc(self): - return self.info - class SubscriptionRegistration(AdapterRegistration): interface.implementsOnly(interfaces.ISubscriptionAdapterRegistration) @@ -516,5 +492,3 @@ def dispatchSubscriptionAdapterRegistrationEvent(registration, event): interfaces.IRegistrationEvent) def dispatchHandlerRegistrationEvent(registration, event): component.handle(registration.handler, event) - - diff --git a/src/zope/component/service.py b/src/zope/component/service.py deleted file mode 100644 index a977d44..0000000 --- a/src/zope/component/service.py +++ /dev/null @@ -1,178 +0,0 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -""" -$Id$ -""" -import warnings - -warnings.warn("This module is deprecated and will go away in Zope 3.5.", - DeprecationWarning, 2) - -import zope.component -from zope.exceptions import DuplicationError -from zope.component.bbb.interfaces import IServiceService -from zope.interface import implements, Interface, directlyProvides - - -class IGlobalServiceManager(IServiceService): - - def defineService(name, interface): - """Define a new service of the given name implementing the given - interface. If the name already exists, raises - DuplicationError""" - - def provideService(name, component): - """Register a service component. - - Provide a service component to do the work of the named - service. If a service component has already been assigned to - this name, raise DuplicationError; if the name has not been - defined, raises UndefinedService; if the component does not - implement the registered interface for the service name, - raises InvalidService. - - """ - -class IService(Interface): - """Marker interface that is used as utility interface to simulate - services.""" - -class IServiceDefinition(Interface): - """Marker interface that is used as utility interface to store service - defintions (name, interface).""" - -class UndefinedService(Exception): - """An attempt to register a service that has not been defined - """ - -class InvalidService(Exception): - """An attempt to register a service that doesn't implement - the required interface - """ - -__warn__ = True -class GlobalServiceManager(object): - """service manager""" - - implements(IGlobalServiceManager) - - def __init__(self, name=None, module=None, sitemanager=None): - if __warn__: - warnings.warn( - "The concept of services has been deprecated. You now have " - "only adapters and utilities, which are managed by the site " - "manager, which is probably the object you want.", - DeprecationWarning, 2) - if sitemanager is None: - from zope.component.globalregistry import BaseGlobalComponents - sitemanager = BaseGlobalComponents() - self.sm = sitemanager - self.__name__ = name - self.__module__ = module - - def _clear(self): - pass - - def __reduce__(self): - # Global service managers are pickled as global objects - return self.__name__ - - def defineService(self, name, interface): - """see IGlobalServiceManager interface""" - - utils = self.sm.getAllUtilitiesRegisteredFor(IServiceDefinition) - names = [n for n, iface in utils] - if name in names: - raise DuplicationError(name) - - self.sm.provideUtility(IServiceDefinition, (name, interface), - name=name, strict=False) - - def getServiceDefinitions(self): - """see IServiceService Interface""" - defs = list(self.sm.getAllUtilitiesRegisteredFor(IServiceDefinition)) - return defs + [('Services', IServiceService)] - - def provideService(self, name, component, force=False): - """see IGlobalServiceManager interface, above - - The force keyword allows one to replace an existing - service. This is mostly useful in testing scenarios. - """ - - if not force and self.sm.queryUtility(IService, name) is not None: - raise DuplicationError(name) - - utils = self.sm.getAllUtilitiesRegisteredFor(IServiceDefinition) - if name not in [name for name, iface in utils]: - raise UndefinedService(name) - - if not dict(self.getServiceDefinitions())[name].providedBy(component): - raise InvalidService(name, component, - dict(self.getServiceDefinitions())[name]) - - if isinstance(component, GlobalService): - component.__parent__ = self - component.__name__ = name - - # Ignore the base services, since their functionality is provided by - # the SM. - if name in ('Adapters', 'Utilities', 'Services'): - return - - directlyProvides(component, IService) - self.sm.provideUtility(IService, component, name) - - def getService(self, name): - """see IServiceService interface""" - if name == 'Services': - return self - - if name == 'Adapters': - from zope.component.bbb.adapter import GlobalAdapterService - return GlobalAdapterService(self.sm) - - if name == 'Utilities': - from zope.component.bbb.utility import GlobalUtilityService - return GlobalUtilityService(self.sm) - - service = self.sm.queryUtility(IService, name) - if service is None: - from zope.component.bbb.exceptions import ComponentLookupError - raise ComponentLookupError(name) - - return service - - -def GS(service_manager, service_name): - return service_manager.getService(service_name) - -class GlobalService(object): - - def __reduce__(self): - return GS, (self.__parent__, self.__name__) - - -def __getSM(sitemanager=None): - return GlobalServiceManager('serviceManager', __name__, sitemanager) - -def defineService(name, interface, sitemanager=None): - if sitemanager is None: - from zope.component.globalregistry import base - __getSM(base).defineService(name, interface) - - -__warn__ = False -serviceManager = GlobalServiceManager('serviceManager', __name__) -__warn__ = True diff --git a/src/zope/component/servicenames.py b/src/zope/component/servicenames.py deleted file mode 100644 index eb9c575..0000000 --- a/src/zope/component/servicenames.py +++ /dev/null @@ -1,24 +0,0 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -""" -$Id$ -""" -import warnings - -warnings.warn("This module is deprecated and will go away in Zope 3.5.", - DeprecationWarning, 2) - -Adapters = 'Adapters' -Utilities = 'Utilities' -Services = 'Services' diff --git a/src/zope/component/site.py b/src/zope/component/site.py deleted file mode 100644 index 22674fe..0000000 --- a/src/zope/component/site.py +++ /dev/null @@ -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. -# -############################################################################## -"""Global Site Manager - -This module has been deprecated and will be removed. Most of the -functionality now resides in the zope.component.globalregistry module. - -$Id$ -""" -__docformat__ = "reStructuredText" - -import warnings -warnings.warn("The zope.component.site module has been deprecated and " - "will be removed. The functionality now resides " - "in the zope.component.globalregistry " - "and zope.component.registry modules.", - DeprecationWarning, stacklevel=2) - -from zope.component.registry import Components as SiteManager -from zope.component.registry import AdapterRegistration -from zope.component.registry import SubscriptionRegistration -from zope.component.registry import UtilityRegistration -from zope.component.globalregistry import BaseGlobalComponents \ - as GlobalSiteManager -from zope.component.globalregistry import base as globalSiteManager -from zope.component.globalregistry import GAR -from zope.component.globalregistry \ - import _IGlobalSiteManager as IGlobalSiteManager diff --git a/src/zope/component/socketexample.txt b/src/zope/component/socketexample.txt index eb5cb15..11bb6fd 100644 --- a/src/zope/component/socketexample.txt +++ b/src/zope/component/socketexample.txt @@ -1,4 +1,3 @@ -================================================== The Zope 3 Component Architecture (Socket Example) ================================================== @@ -75,7 +74,7 @@ Note that I could have called the passed in socket any way I like, but Single Adapters -+++++++++++++++ +~~~~~~~~~~~~~~~ Before we can use the adapter, we have to buy it and make it part of our inventory. In the component architecture we do this by registering the adapter @@ -142,7 +141,7 @@ always return a `default` value after a failure. Named Adapters -++++++++++++++ +~~~~~~~~~~~~~~ You are finally back in Germany. You also brought your DVD player and a couple DVDs with you, which you would like to watch. Your shaver was able to convert @@ -204,7 +203,7 @@ adapter itself. Multi-Adapters -++++++++++++++ +~~~~~~~~~~~~~~ After watching all the DVDs you brought at least twice, you get tired of them and you want to listen to some music using your MP3 player. But darn, the MP3 @@ -408,7 +407,7 @@ will never cause a `ComponentLookupError`. Named Utilities -+++++++++++++++ +~~~~~~~~~~~~~~~ It is often desirable to have several utilities providing the same interface per site. This way you can implement any sort of registry using utilities. For @@ -475,7 +474,7 @@ need this method. Factories -+++++++++ +~~~~~~~~~ A *factory* is a special kind of utility that exists to create other components. A factory is always identified by a name. It also provides a title @@ -596,5 +595,3 @@ We can now ask for the site manager of this context: The site manager instance `lsm` is formally known as a *local site manager* of `context`. - - diff --git a/src/zope/component/utility.py b/src/zope/component/utility.py deleted file mode 100644 index cd71470..0000000 --- a/src/zope/component/utility.py +++ /dev/null @@ -1,76 +0,0 @@ -############################################################################## -# -# Copyright (c) 2001, 2002 Zope Corporation and Contributors. -# All Rights Reserved. -# -# This software is subject to the provisions of the Zope Public License, -# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. -# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED -# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS -# FOR A PARTICULAR PURPOSE. -# -############################################################################## -""" -$Id$ -""" -import warnings - -warnings.warn("This module is deprecated and will go away in Zope 3.5.", - DeprecationWarning, 2) - -from zope.component.interfaces import Invalid, ComponentLookupError, IRegistry -from zope.component.bbb.interfaces import IUtilityService -from zope.component.service import GlobalService, IService, IServiceDefinition -from zope.component.registry import UtilityRegistration -import zope.interface - -class IGlobalUtilityService(IUtilityService, IRegistry): - - def provideUtility(providedInterface, component, name='', info=''): - """Provide a utility - - A utility is a component that provides an interface. - """ - -class UtilityService(object): - """Provide IUtilityService - - Mixin that superimposes utility management on adapter registery - implementation - """ - - def __init__(self, sitemanager=None): - self.__parent__ = None - if sitemanager is None: - from zope.component.site import GlobalSiteManager - sitemanager = GlobalSiteManager() - self.sm = sitemanager - - def __getattr__(self, name): - attr = getattr(self.sm, name) - if attr is not None: - return attr - - attr = getattr(self.sm.utilities, name) - if attr is not None: - return attr - - raise AttributeError(name) - - -class GlobalUtilityService(UtilityService, GlobalService): - - zope.interface.implementsOnly(IGlobalUtilityService) - - def __init__(self, sitemanager=None): - super(GlobalUtilityService, self).__init__(sitemanager) - - def provideUtility(self, providedInterface, component, name='', info=''): - self.sm.provideUtility(providedInterface, component, name, info) - - def registrations(self): - for reg in self.sm.registrations(): - if isinstance(reg, UtilityRegistration): - if not reg.provided in (IService, IServiceDefinition): - yield reg |
