o ,W A@sdZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lm Z dd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGdddeZGdddeZGdddeZGdd d eZGd!d"d"eZGd#d$d$e Z!Gd%d&d&eZ"d'S)(z0Component and Component Architecture Interfaces ) Attribute) Interface) implements)ComponentLookupError)Invalid) IObjectEvent) ObjectEvent)IComponentLookup) IRegistration)IUtilityRegistration)_IBaseAdapterRegistration)IAdapterRegistration) ISubscriptionAdapterRegistration)IHandlerRegistration)IRegistrationEvent)RegistrationEvent) IRegistered) Registered) IUnregistered) Unregistered)IComponentRegistry) IComponents)_BLANKc@seZdZdZddZd.ddZd/dd Zd0d d Zd/d d Zd1ddZ d.ddZ d.ddZ e e dfddZddZe ddfddZe e ddfddZd.ddZe e ddfddZd.d d!Zd.d"d#Zd$d%Zd&d'Zd(d)Zd.d*d+Zd.d,d-ZdS)2IComponentArchitecturezThe Component Architecture is defined by two key components: Adapters and Utiltities. Both are managed by site managers. All other components build on top of them. cCdS)zReturn the global site manager. This function should never fail and always return an object that provides `IGlobalSiteManager`. Nrrr;/usr/lib/python3/dist-packages/zope/component/interfaces.pygetGlobalSiteManager3z+IComponentArchitecture.getGlobalSiteManagerNcCr)aHGet the nearest site manager in the given context. If `context` is `None`, return the global site manager. If the `context` is not `None`, it is expected that an adapter from the `context` to `IComponentLookup` can be found. If no adapter is found, a `ComponentLookupError` is raised. Nr)contextrrrgetSiteManager:rz%IComponentArchitecture.getSiteManagercCr)zGet the utility that provides interface Returns the nearest utility to the context that implements the specified interface. If one is not found, raises ComponentLookupError. Nr) interfacenamerrrr getUtilityGrz!IComponentArchitecture.getUtilitycCr)zLook 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. Nr)r"r#defaultrrrr queryUtilityOrz#IComponentArchitecture.queryUtilitycCr)zQuery 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. Nr)rr"r#r%rrrqueryNextUtilityVrz'IComponentArchitecture.queryNextUtilitycCr)zrGet the next available utility. If no utility was found, a `ComponentLookupError` is raised. Nr)rr"r#rrrgetNextUtility^rz%IComponentArchitecture.getNextUtilitycCr)zuReturn the utilities that provide an interface An iterable of utility name-value pairs is returned. Nrr"rrrrgetUtilitiesFordrz&IComponentArchitecture.getUtilitiesForcCr)zReturn all registered utilities for an interface This includes overridden utilities. An iterable of utility instances is returned. No names are returned. Nrr)rrrgetAllUtilitiesRegisteredForjrz3IComponentArchitecture.getAllUtilitiesRegisteredForcCr)aGet 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. If context is None, an application-defined policy is used to choose an appropriate service manager from which to get an 'Adapters' service. If 'context' is not None, context is adapted to IServiceService, and this adapter's 'Adapters' service is used. Nr)objectr"r#rrrr getAdapterurz!IComponentArchitecture.getAdaptercCr)a)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. Context is adapted to IServiceService, and this adapter's 'Adapters' service is used. 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. Nr)r,r"rrrrgetAdapterInContextrz*IComponentArchitecture.getAdapterInContextcCr)aLook 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. If context is None, an application-defined policy is used to choose an appropriate service manager from which to get an 'Adapters' service. If 'context' is not None, context is adapted to IServiceService, and this adapter's 'Adapters' service is used. 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. Nr)objectsr"r#rrrrgetMultiAdapterrz&IComponentArchitecture.getMultiAdaptercCr)aLook 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. If context is None, an application-defined policy is used to choose an appropriate service manager from which to get an 'Adapters' service. If 'context' is not None, context is adapted to IServiceService, and this adapter's 'Adapters' service is used. Nr)r,r"r#r%rrrr queryAdapterrz#IComponentArchitecture.queryAdaptercCr)a/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. Context is adapted to IServiceService, and this adapter's 'Adapters' service is used. 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. Nr)r,r"rr%rrrqueryAdapterInContextrz,IComponentArchitecture.queryAdapterInContextcCr)aLook 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. If context is None, an application-defined policy is used to choose an appropriate service manager from which to get an 'Adapters' service. If 'context' is not None, context is adapted to IServiceService, and this adapter's 'Adapters' service is used. 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. Nr)r/r"r#r%rrrrqueryMultiAdapterrz(IComponentArchitecture.queryMultiAdaptercCr)aLook 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. If context is None, an application-defined policy is used to choose an appropriate service manager from which to get an 'Adapters' service. If 'context' is not None, context is adapted to IServiceService, and this adapter's 'Adapters' service is used. Nr)r/providedrrrr getAdaptersrz"IComponentArchitecture.getAdapterscCr)aGet subscribers Subscribers are returned that provide the provided interface and that depend on and are computed from the sequence of required objects. If context is None, an application-defined policy is used to choose an appropriate service manager from which to get an 'Adapters' service. If 'context' is not None, context is adapted to IServiceService, and this adapter's 'Adapters' service is used. Nr)requiredr4rrrr subscribersrz"IComponentArchitecture.subscriberscGr)zCall 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. Nr)r/rrrhandlerzIComponentArchitecture.handlecGr)zDeclare that a class adapts the given interfaces. This function can only be used in a class definition. (TODO, allow classes to be passed as well as interfaces.) Nr) interfacesrrradapts rzIComponentArchitecture.adaptscOr)aCreate 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. Nr) factory_nameargskwargsrrr createObjectrz#IComponentArchitecture.createObjectcCr)zGet 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. Nr)r#rrrrgetFactoryInterfaces#rz+IComponentArchitecture.getFactoryInterfacescCr)zReturn a tuple (name, factory) of registered factories that create objects which implement the given interface. Nrr)rrrgetFactoriesFor+rz&IComponentArchitecture.getFactoriesForN)r!N)r!NN)r!)__name__ __module__ __qualname____doc__rr r$r&r'r(r*r+rrr-r.r0r1r2r3r5r7r8r:r>r?r@rrrrr,s@              rc@seZdZdZddZdS) IRegistryz,Object that supports component registry cCr)z6Return an iterable of component registrations Nrrrrr registrations5rzIRegistry.registrationsN)rBrCrDrErGrrrrrF1s rFc@sBeZdZdZdefddZddefddZd ddZd d d ZdS) !IComponentRegistrationConveniencezAPI for registering components. CAUTION: This API should only be used from test or application-setup code. This api shouldn't be used by regular library modules, as component registration is a configuration activity. NcCr)aBRegister 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.) CAUTION: This API should only be used from test or application-setup code. This API shouldn't be used by regular library modules, as component registration is a configuration activity. Nr) componentprovidesr#rrrprovideUtilityBrz0IComponentRegistrationConvenience.provideUtilitycCr)a=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.) CAUTION: This API should only be used from test or application-setup code. This API shouldn't be used by regular library modules, as component registration is a configuration activity. Nr)factoryr:rJr#rrrprovideAdapterRrz0IComponentRegistrationConvenience.provideAdaptercCr)a@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.) CAUTION: This API should only be used from test or application-setup code. This API shouldn't be used by regular library modules, as component registration is a configuration activity. Nr)rLr:rJrrrprovideSubscriptionAdapterfrzsB                       S