U
    [eY%                     @   sN   d dl Z ddlmZ ddlmZ e eZG dd deZG dd deZ	dS )	    N   )EnabledExtensionManager)	NoMatchesc                   @   s    e Zd ZdZdd Zdd ZdS )DispatchExtensionManageraF  Loads all plugins and filters on execution.

    This is useful for long-running processes that need to pass
    different inputs to different extensions.

    :param namespace: The namespace for the entry points.
    :type namespace: str
    :param check_func: Function to determine which extensions to load.
    :type check_func: callable
    :param invoke_on_load: Boolean controlling whether to invoke the
        object returned by the entry point after the driver is loaded.
    :type invoke_on_load: bool
    :param invoke_args: Positional arguments to pass when invoking
        the object returned by the entry point. Only used if invoke_on_load
        is True.
    :type invoke_args: tuple
    :param invoke_kwds: Named arguments to pass when invoking
        the object returned by the entry point. Only used if invoke_on_load
        is True.
    :type invoke_kwds: dict
    :param propagate_map_exceptions: Boolean controlling whether exceptions
        are propagated up through the map call or whether they are logged and
        then ignored
    :type invoke_on_load: bool
    c                 O   sL   | j std| j g }| j D ](}||f||r| |j|||| q|S )a|  Iterate over the extensions invoking func() for any where
        filter_func() returns True.

        The signature of filter_func() should be::

            def filter_func(ext, *args, **kwds):
                pass

        The first argument to filter_func(), 'ext', is the
        :class:`~stevedore.extension.Extension`
        instance. filter_func() should return True if the extension
        should be invoked for the input arguments.

        The signature for func() should be::

            def func(ext, *args, **kwds):
                pass

        The first argument to func(), 'ext', is the
        :class:`~stevedore.extension.Extension` instance.

        Exceptions raised from within func() are propagated up and
        processing stopped if self.propagate_map_exceptions is True,
        otherwise they are logged and ignored.

        :param filter_func: Callable to test each extension.
        :param func: Callable to invoke for each extension.
        :param args: Variable arguments to pass to func()
        :param kwds: Keyword arguments to pass to func()
        :returns: List of values returned from func()
        zNo %s extensions found)
extensionsr   	namespace_invoke_one_pluginappend)selffilter_funcfuncargskwdsresponsee r   T/var/www/html/services/stratfitenv/lib/python3.8/site-packages/stevedore/dispatch.pymap0   s     
zDispatchExtensionManager.mapc                 O   s   | j || j|f||S )aU  Iterate over the extensions invoking each one's object method called
        `method_name` for any where filter_func() returns True.

        This is equivalent of using :meth:`map` with func set to
        `lambda x: x.obj.method_name()`
        while being more convenient.

        Exceptions raised from within the called method are propagated up
        and processing stopped if self.propagate_map_exceptions is True,
        otherwise they are logged and ignored.

        .. versionadded:: 0.12

        :param filter_func: Callable to test each extension.
        :param method_name: The extension method name to call
                            for each extension.
        :param args: Variable arguments to pass to method
        :param kwds: Keyword arguments to pass to method
        :returns: List of values returned from methods
        r   Z_call_extension_method)r
   r   method_namer   r   r   r   r   
map_methodY   s    
z#DispatchExtensionManager.map_methodN)__name__
__module____qualname____doc__r   r   r   r   r   r   r      s   )r   c                       sJ   e Zd ZdZddi dddf fdd	Z fddZd	d
 Zdd Z  ZS )NameDispatchExtensionManagera6  Loads all plugins and filters on execution.

    This is useful for long-running processes that need to pass
    different inputs to different extensions and can predict the name
    of the extensions before calling them.

    The check_func argument should return a boolean, with ``True``
    indicating that the extension should be loaded and made available
    and ``False`` indicating that the extension should be ignored.

    :param namespace: The namespace for the entry points.
    :type namespace: str
    :param check_func: Function to determine which extensions to load.
    :type check_func: callable
    :param invoke_on_load: Boolean controlling whether to invoke the
        object returned by the entry point after the driver is loaded.
    :type invoke_on_load: bool
    :param invoke_args: Positional arguments to pass when invoking
        the object returned by the entry point. Only used if invoke_on_load
        is True.
    :type invoke_args: tuple
    :param invoke_kwds: Named arguments to pass when invoking
        the object returned by the entry point. Only used if invoke_on_load
        is True.
    :type invoke_kwds: dict
    :param propagate_map_exceptions: Boolean controlling whether exceptions
        are propagated up through the map call or whether they are logged and
        then ignored
    :type invoke_on_load: bool
    :param on_load_failure_callback: Callback function that will be called when
        an entrypoint can not be loaded. The arguments that will be provided
        when this is called (when an entrypoint fails to load) are
        (manager, entrypoint, exception)
    :type on_load_failure_callback: function
    :param verify_requirements: Use setuptools to enforce the
        dependencies of the plugin(s) being loaded. Defaults to False.
    :type verify_requirements: bool

    Fr   Nc	           	   
      s$   t t| j||||||||d d S )N)r   
check_funcinvoke_on_loadinvoke_argsinvoke_kwdspropagate_map_exceptionson_load_failure_callbackverify_requirements)superr   __init__)	r
   r   r   r   r   r   r    r!   r"   	__class__r   r   r$      s    
z%NameDispatchExtensionManager.__init__c                    s*   t t| | tdd | jD | _d S )Nc                 s   s   | ]}|j |fV  qd S )N)name).0r   r   r   r   	<genexpr>   s     z=NameDispatchExtensionManager._init_plugins.<locals>.<genexpr>)r#   r   _init_pluginsdictr   by_name)r
   r   r%   r   r   r*      s    z*NameDispatchExtensionManager._init_pluginsc              	   O   sV   g }|D ]H}z| j | }W n  tk
r:   td| Y qX | |j|||| q|S )a5  Iterate over the extensions invoking func() for any where
        the name is in the given list of names.

        The signature for func() should be::

            def func(ext, *args, **kwds):
                pass

        The first argument to func(), 'ext', is the
        :class:`~stevedore.extension.Extension` instance.

        Exceptions raised from within func() are propagated up and
        processing stopped if self.propagate_map_exceptions is True,
        otherwise they are logged and ignored.

        :param names: List or set of name(s) of extension(s) to invoke.
        :param func: Callable to invoke for each extension.
        :param args: Variable arguments to pass to func()
        :param kwds: Keyword arguments to pass to func()
        :returns: List of values returned from func()
        z"Missing extension %r being ignored)r,   KeyErrorLOGdebugr   r	   )r
   namesr   r   r   r   r'   r   r   r   r   r      s    z NameDispatchExtensionManager.mapc                 O   s   | j || j|f||S )al  Iterate over the extensions invoking each one's object method called
        `method_name` for any where the name is in the given list of names.

        This is equivalent of using :meth:`map` with func set to
        `lambda x: x.obj.method_name()`
        while being more convenient.

        Exceptions raised from within the called method are propagated up
        and processing stopped if self.propagate_map_exceptions is True,
        otherwise they are logged and ignored.

        .. versionadded:: 0.12

        :param names: List or set of name(s) of extension(s) to invoke.
        :param method_name: The extension method name
                            to call for each extension.
        :param args: Variable arguments to pass to method
        :param kwds: Keyword arguments to pass to method
        :returns: List of values returned from methods
        r   )r
   r0   r   r   r   r   r   r   r      s    
z'NameDispatchExtensionManager.map_method)	r   r   r   r   r$   r*   r   r   __classcell__r   r   r%   r   r   r   s   (  r   )
loggingenabledr   	exceptionr   	getLoggerr   r.   r   r   r   r   r   r   <module>   s
   
]