U
    [eB                     @   s2   d dl Z ddlmZ e eZG dd deZdS )    N   )ExtensionManagerc                	       sd   e Zd ZdZddi ddddddf	ddZedd	d
Zd fdd	Z fddZ fddZ	  Z
S )NamedExtensionManageran  Loads only the named extensions.

    This is useful for explicitly enabling extensions in a
    configuration file, for example.

    :param namespace: The namespace for the entry points.
    :type namespace: str
    :param names: The names of the extensions to load.
    :type names: list(str)
    :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 name_order: If true, sort the loaded extensions to match the
        order used in ``names``.
    :type name_order: bool
    :param propagate_map_exceptions: Boolean controlling whether exceptions
        are propagated up through the map call or whether they are logged and
        then ignored
    :type propagate_map_exceptions: 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 on_missing_entrypoints_callback: Callback function that will be
        called when one or more names cannot be found. The provided argument
        will be a subset of the 'names' parameter.
    :type on_missing_entrypoints_callback: function
    :param verify_requirements: Use setuptools to enforce the
        dependencies of the plugin(s) being loaded. Defaults to False.
    :type verify_requirements: bool
    :param warn_on_missing_entrypoint: Flag to control whether failing
        to load a plugin is reported via a log mess. Only applies if
        on_missing_entrypoints_callback is None.
    :type warn_on_missing_entrypoint: bool

    F NTc                 C   s~   | j |||||d | ||||
}t|tdd |D  | _| jrp|	rV|	| j n|rptdd| j  | | d S )N)
name_orderpropagate_map_exceptionson_load_failure_callbackc                 S   s   g | ]
}|j qS r   name.0er   r   Q/var/www/html/services/stratfitenv/lib/python3.8/site-packages/stevedore/named.py
<listcomp>R   s     z2NamedExtensionManager.__init__.<locals>.<listcomp>zCould not load %sz, )_init_attributesZ_load_pluginsset_missing_namesLOGwarningjoin_init_plugins)self	namespacenamesinvoke_on_loadinvoke_argsinvoke_kwdsr   r   r   Zon_missing_entrypoints_callbackverify_requirementsZwarn_on_missing_entrypoint
extensionsr   r   r   __init__C   s*      
zNamedExtensionManager.__init__TESTINGc                 C   s8   |  | }dd |D }|j||||d || |S )a  Construct a test NamedExtensionManager

        Test instances are passed a list of extensions to use rather than
        loading them from entry points.

        :param extensions: Pre-configured Extension instances
        :type extensions: list of :class:`~stevedore.extension.Extension`
        :param namespace: The namespace for the manager; used only for
            identification since the extensions are passed in.
        :type namespace: str
        :param propagate_map_exceptions: Boolean controlling whether exceptions
            are propagated up through the map call or whether they are logged
            and then ignored
        :type propagate_map_exceptions: 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
        :return: The manager instance, initialized for testing

        c                 S   s   g | ]
}|j qS r   r	   r   r   r   r   r   |   s     z<NamedExtensionManager.make_test_instance.<locals>.<listcomp>r   r   )__new__r   r   )clsr   r   r   r   r   or   r   r   r   make_test_instance[   s     

z(NamedExtensionManager.make_test_instancec                    s.   t t| j|||d || _t | _|| _d S )Nr!   )superr   r   _namesr   r   _name_order)r   r   r   r   r   r   	__class__r   r   r      s    
 z&NamedExtensionManager._init_attributesc                    s0   t t |  jr, fdd jD  _d S )Nc                    s   g | ]}| j kr | qS r   )r   )r   nr   r   r   r      s    
z7NamedExtensionManager._init_plugins.<locals>.<listcomp>)r&   r   r   r(   r'   r   )r   r   r)   r,   r   r      s    z#NamedExtensionManager._init_pluginsc                    s(   |j | jkrd S tt| |||||S )N)r
   r'   r&   r   _load_one_plugin)r   epr   r   r   r   r)   r   r   r-      s    
   z&NamedExtensionManager._load_one_plugin)r    FNF)FFN)__name__
__module____qualname____doc__r   classmethodr%   r   r   r-   __classcell__r   r   r)   r   r      s.   /   
    '   r   )logging	extensionr   	getLoggerr/   r   r   r   r   r   r   <module>   s   
