3 ,�W A � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z dd lm Z dd lmZ ddlmZ ddlm Z dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ G dd� de�ZG dd� de�ZG dd� de�ZG dd � d e�ZG d!d"� d"e�ZG d#d$� d$e �Z!G d%d&� d&e�Z"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 @ s� e Zd ZdZdd� Zd.dd�Zd/dd �Zd0d d�Zd1dd �Zd2dd�Z d3dd�Z d4dd�Zee dfdd�Zdd� Zeddfdd�Zee ddfdd�Zd5dd�Zee ddfdd�Zd6d d!�Zd7d"d#�Zd$d%� Zd&d'� Zd(d)� Zd8d*d+�Zd9d,d-�ZdS ):�IComponentArchitecturez�The 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. c C s dS )z�Return the global site manager. This function should never fail and always return an object that provides `IGlobalSiteManager`. N� r r r � /usr/lib/python3.6/interfaces.py�getGlobalSiteManager3 s z+IComponentArchitecture.getGlobalSiteManagerNc C s dS )aH Get 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 )�contextr r r �getSiteManager: s z%IComponentArchitecture.getSiteManager� c C s dS )z�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. Nr )� interface�namer r r r � getUtilityG s z!IComponentArchitecture.getUtilityc C s dS )z�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. Nr )r r! �defaultr r r r �queryUtilityO s z#IComponentArchitecture.queryUtilityc C s dS )z�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. Nr )r r r! r# r r r �queryNextUtilityV s z'IComponentArchitecture.queryNextUtilityc C s dS )zrGet the next available utility. If no utility was found, a `ComponentLookupError` is raised. Nr )r r r! r r r �getNextUtility^ s z%IComponentArchitecture.getNextUtilityc C s dS )zuReturn the utilities that provide an interface An iterable of utility name-value pairs is returned. Nr )r r r r r �getUtilitiesFord s z&IComponentArchitecture.getUtilitiesForc C s dS )z�Return all registered utilities for an interface This includes overridden utilities. An iterable of utility instances is returned. No names are returned. Nr )r r r r r �getAllUtilitiesRegisteredForj s z3IComponentArchitecture.getAllUtilitiesRegisteredForc C s dS )a� 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. 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! r r r r � getAdapteru s z!IComponentArchitecture.getAdapterc C s dS )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 r r r r �getAdapterInContext� s z*IComponentArchitecture.getAdapterInContextc C s dS )a� 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. 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! r r r r �getMultiAdapter� s z&IComponentArchitecture.getMultiAdapterc C s dS )a� 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. 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# r r r r �queryAdapter� s z#IComponentArchitecture.queryAdapterc C s dS )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 r r# r r r �queryAdapterInContext� s z,IComponentArchitecture.queryAdapterInContextc C s dS )a� 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. 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# r r r r �queryMultiAdapter� s z(IComponentArchitecture.queryMultiAdapterc C s dS )a� 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. 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, �providedr r r r �getAdapters� s z"IComponentArchitecture.getAdaptersc C s dS )a� Get 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 )Zrequiredr1 r r r r �subscribers� s z"IComponentArchitecture.subscribersc G s dS )z�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. Nr )r, r r r �handle s zIComponentArchitecture.handlec G s dS )z�Declare 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 )Z interfacesr r r �adapts s zIComponentArchitecture.adaptsc O s dS )a� 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. Nr )Zfactory_name�args�kwargsr r r �createObject s z#IComponentArchitecture.createObjectc C s dS )z�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. Nr )r! r r r r �getFactoryInterfaces# s z+IComponentArchitecture.getFactoryInterfacesc C s dS )z�Return a tuple (name, factory) of registered factories that create objects which implement the given interface. Nr )r r r r r �getFactoriesFor+ s z&IComponentArchitecture.getFactoriesFor)N)r N)r NN)r N)r )N)N)N)N)N)N)N)�__name__� __module__�__qualname__�__doc__r r r"