zope.component: Module-level functions¶
This document provides a summary of the APIs available directly from
zope.component. For more details, see the remaining documentation.
Zope 3 Component Architecture
This module provides an implementation of
IComponentArchitecture, using the
current site.
This module also provides an implementation of
IComponentRegistrationConvenience
using the global site manager.
- class zope.component.adapter(*interfaces)[source]
Bases:
objectDecorator that declares that the decorated object adapts the given interfaces.
This is commonly used in conjunction with
zope.interface.implementerto declare what adapting the interfaces will provide.
- zope.component.adaptedBy(ob)[source]
Return the interfaces that ob will adapt, as declared by
adapter.
- zope.component.createObject(__factory_name, *args, **kwargs)[source]
Create an object using a factory
Finds the named factory in the current site and calls it with the given arguments. If a matching factory cannot be found raises
ComponentLookupError. Returns the created object.A context keyword argument can be provided to cause the factory to be looked up in a location other than the current site. (Of course, this means that it is impossible to pass a keyword argument named “context” to the factory.
See also
Function
createObjectfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getAdapter(object, interface=<InterfaceClass zope.interface.Interface>, name='', context=None)[source]
Get a named adapter to an interface for an object
Returns an adapter that can adapt object to interface. If a matching adapter cannot be found, raises
ComponentLookupError.See also
Function
getAdapterfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getAdapterInContext(object, interface, context)[source]
Get a special adapter to an interface for an object
Note
This method should only be used if a custom context needs to be provided to provide custom component lookup. Otherwise, call the interface, as in:
interface(object)
Returns an adapter that can adapt object to interface. If a matching adapter cannot be found, raises
ComponentLookupError.If the object has a
__conform__method, this method will be called with the requested interface. If the method returns a non-None value, that value will be returned. Otherwise, if the object already implements the interface, the object will be returned.See also
Function
getAdapterInContextfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getAdapters(objects, provided, context=None)[source]
Look for all matching adapters to a provided interface for objects
Return a list of adapters that match. If an adapter is named, only the most specific adapter of a given name is returned.
See also
Function
getAdaptersfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getAllUtilitiesRegisteredFor(interface, context=None)[source]
Return all registered utilities for an interface
This includes overridden utilities.
An iterable of utility instances is returned. No names are returned.
See also
Function
getAllUtilitiesRegisteredForfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getFactoriesFor(interface, context=None)[source]
Return a tuple (name, factory) of registered factories that create objects which implement the given interface.
See also
Function
getFactoriesForfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getFactoryInterfaces(name, context=None)[source]
Get interfaces implemented by a factory
Finds the factory of the given name that is nearest to the context, and returns the interface or interface tuple that object instances created by the named factory will implement.
See also
Function
getFactoryInterfacesfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getGlobalSiteManager()[source]
Return the global site manager.
This function should never fail and always return an object that provides
zope.interface.interfaces.IComponents.See also
Function
getGlobalSiteManagerfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getMultiAdapter(objects, interface=<InterfaceClass zope.interface.Interface>, name='', context=None)[source]
Look for a multi-adapter to an interface for an objects
Returns a multi-adapter that can adapt objects to interface. If a matching adapter cannot be found, raises
ComponentLookupError.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.
See also
Function
getMultiAdapterfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getNextUtility(context, interface, name='')[source]
Get the next available utility.
If no utility was found, a
ComponentLookupErroris raised.See also
Function
getNextUtilityfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getUtilitiesFor(interface, context=None)[source]
Return the utilities that provide an interface
An iterable of utility name-value pairs is returned.
See also
Function
getUtilitiesForfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.getUtility(interface, name='', context=None)[source]
Get the utility that provides interface
Returns the nearest utility to the context that implements the specified interface. If one is not found, raises
ComponentLookupError.See also
Function
getUtilityfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.handle(*objects)[source]
Call all of the handlers for the given objects
Handlers are subscription adapter factories that don’t produce anything. They do all of their work when called. Handlers are typically used to handle events.
See also
Function
handlefor notes, andIComponentArchitecturefor the defining interface.
- zope.component.provideAdapter(factory, adapts=None, provides=None, name='')[source]
Register an adapter globally
An adapter is registered to provide an interface with a name for some number of object types. If a factory implements only one interface, then the provides argument can be omitted and the provided interface will be used. (In this case, a provides argument can still be provided to provide a less specific interface.)
If the factory has an adapts declaration, then the adapts argument can be omitted and the declaration will be used. (An adapts argument can be provided to override the declaration.)
See also
Function
provideAdapterfor notes, andIComponentRegistrationConveniencefor the defining interface.
- zope.component.provideHandler(factory, adapts=None)[source]
Register a handler
Handlers are subscription adapter factories that don’t produce anything. They do all of their work when called. Handlers are typically used to handle events.
If the handler has an adapts declaration, then the adapts argument can be omitted and the declaration will be used. (An adapts argument can be provided to override the declaration.)
See also
Function
provideHandlerfor notes, andIComponentRegistrationConveniencefor the defining interface.
- zope.component.provideSubscriptionAdapter(factory, adapts=None, provides=None)[source]
Register a subscription adapter
A subscription adapter is registered to provide an interface for some number of object types. If a factory implements only one interface, then the provides argument can be omitted and the provided interface will be used. (In this case, a provides argument can still be provided to provide a less specific interface.)
If the factory has an adapts declaration, then the adapts argument can be omitted and the declaration will be used. (An adapts argument can be provided to override the declaration.)
See also
Function
provideSubscriptionAdapterfor notes, andIComponentRegistrationConveniencefor the defining interface.
- zope.component.provideUtility(component, provides=None, name='')[source]
Register a utility globally
A utility is registered to provide an interface with a name. If a component provides only one interface, then the provides argument can be omitted and the provided interface will be used. (In this case, provides argument can still be provided to provide a less specific interface.)
See also
Function
provideUtilityfor notes, andIComponentRegistrationConveniencefor the defining interface.
- zope.component.queryAdapter(object, interface=<InterfaceClass zope.interface.Interface>, name='', default=None, context=None)[source]
Look for a named adapter to an interface for an object
Returns an adapter that can adapt object to interface. If a matching adapter cannot be found, returns the default.
See also
Function
queryAdapterfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.queryAdapterInContext(object, interface, context, default=None)[source]
Look for a special adapter to an interface for an object
Note
This method should only be used if a custom context needs to be provided to provide custom component lookup. Otherwise, call the interface, as in:
interface(object, default)
Returns an adapter that can adapt object to interface. If a matching adapter cannot be found, returns the default.
If the object has a
__conform__method, this method will be called with the requested interface. If the method returns a non-None value, that value will be returned. Otherwise, if the object already implements the interface, the object will be returned.See also
Function
queryAdapterInContextfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.queryMultiAdapter(objects, interface=<InterfaceClass zope.interface.Interface>, name='', default=None, context=None)[source]
Look for a multi-adapter to an interface for objects
Returns a multi-adapter that can adapt objects to interface. 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.
See also
Function
queryMultiAdapterfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.queryNextUtility(context, interface, name='', default=None)[source]
Query for the next available utility.
Find the next available utility providing interface and having the specified name. If no utility was found, return the specified default value.
See also
Function
queryNextUtilityfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.queryUtility(interface, name='', default=None, context=None)[source]
Look for the utility that provides interface
Returns the nearest utility to the context that implements the specified interface. If one is not found, returns default.
See also
Function
queryUtilityfor notes, andIComponentArchitecturefor the defining interface.
- zope.component.subscribers(objects, interface, context=None)[source]
Get subscribers
Subscribers are returned that provide the provided interface and that depend on and are computed from the sequence of required objects.
See also
Function
subscribersfor notes, andIComponentArchitecturefor the defining interface.