
    dH                          d dl Z d dlmZmZmZmZmZmZmZ d dl	m
Z
 e j        dk    rd dlmZ nd dlmZ d dlmZ  ed          Z G d d	e          Z G d
 d          Z G d dee                   Zd ZdS )    N)AnyDictListOptionalGenericTypeVarcast)TracebackType)      )entry_points)curry
PluginTypec                       e Zd Zd Zd ZdS )NoSuchEntryPointc                 "    || _         || _        d S N)groupname)selfr   r   s      <lib/python3.11/site-packages/altair/utils/plugin_registry.py__init__zNoSuchEntryPoint.__init__   s    
			    c                 &    d| j         d| j        S )NzNo z entry point found in group )r   r   r   s    r   __str__zNoSuchEntryPoint.__str__   s    LTYLLdjLLLr   N)__name__
__module____qualname__r   r    r   r   r   r      s7          M M M M Mr   r   c                   N    e Zd ZdZdddefdZddZded	ed
e	ddfdZ
defdZdS )PluginEnablera  Context manager for enabling plugins

    This object lets you use enable() as a context manager to
    temporarily enable a given plugin::

        with plugins.enable('name'):
            do_something()  # 'name' plugin temporarily enabled
        # plugins back to original state
    registryPluginRegistryr   c                     || _         || _        || _        |                                | _         | j         j        |fi | d S r   )r#   r   options
_get_stateoriginal_state_enable)r   r#   r   r&   s       r   r   zPluginEnabler.__init__$   sN     	&1133d..g.....r   returnc                     | S r   r    r   s    r   	__enter__zPluginEnabler.__enter__+   s    r   typvalue	tracebackNc                 D    | j                             | j                   d S r   )r#   
_set_stater(   )r   r-   r.   r/   s       r   __exit__zPluginEnabler.__exit__.   s!      !455555r   c                 V    d                     | j        j        j        | j                  S )Nz{}.enable({!r}))formatr#   	__class__r   r   r   s    r   __repr__zPluginEnabler.__repr__1   s"     ''(?(H$)TTTr   )r*   r"   )r   r   r   __doc__strr   r,   type	Exceptionr
   r2   r6   r    r   r   r"   r"      s         /!1 / / / / /   6D 6 6} 6QU 6 6 6 6U# U U U U U Ur   r"   c                   J   e Zd ZdZi Zi ZdefdedefdZ	dede
e         de
e         fd	Zdee         fd
Zdeeef         fdZdeeef         ddfdZdeddfdZdde
e         defdZedefd            Zedeeef         fd            Zde
e         fdZdefdZdS )r$   a  A registry for plugins.

    This is a plugin registry that allows plugins to be loaded/registered
    in two ways:

    1. Through an explicit call to ``.register(name, value)``.
    2. By looking for other Python packages that are installed and provide
       a setuptools entry point group.

    When you create an instance of this class, provide the name of the
    entry point group to use::

        reg = PluginRegister('my_entrypoint_group')

     entry_point_groupplugin_typec                     || _         || _        d| _        d| _        i | _        i | _        | j        j                                        | _        dS )aJ  Create a PluginRegistry for a named entry point group.

        Parameters
        ==========
        entry_point_group: str
            The name of the entry point group.
        plugin_type: object
            A type that will optionally be used for runtime type checking of
            loaded plugins using isinstance.
        Nr<   )	r=   r>   _active_active_name_plugins_optionsr5   _global_settingscopy)r   r=   r>   s      r   r   zPluginRegistry.__init__N   sP     "3& $ ? D D F Fr   r   r.   r*   c                     || j                             |d          S t          || j                  sJ || j         |<   |S )a  Register a plugin by name and value.

        This method is used for explicit registration of a plugin and shouldn't be
        used to manage entry point managed plugins, which are auto-loaded.

        Parameters
        ==========
        name: str
            The name of the plugin.
        value: PluginType or None
            The actual plugin object to register or None to unregister that plugin.

        Returns
        =======
        plugin: PluginType or None
            The plugin that was registered or unregistered.
        N)rB   pop
isinstancer>   )r   r   r.   s      r   registerzPluginRegistry.registera   sK    $ ==$$T4000eT%566666"'DM$Lr   c                     t          | j                                                  }t          | j                  }d |D             }|                    |           t          t          |                    S )z:List the names of the registered and entry points plugins.c                     g | ]	}|j         
S r    r   ).0eps     r   
<listcomp>z(PluginRegistry.names.<locals>.<listcomp>~   s    000RW000r   )listrB   keysimportlib_metadata_getr=   extendsortedset)r   extse_points	more_extss       r   nameszPluginRegistry.namesz   sf    DM&&(()))$*@AA00x000	Ic$ii   r   c                     | j         | j        | j                                        | j                                        | j                                        dS )zBReturn a dictionary representing the current state of the registry)r@   rA   rB   rC   rD   )r@   rA   rB   rE   rC   rD   r   s    r   r'   zPluginRegistry._get_state   sR     | -**,,**,, $ 5 : : < <
 
 	
r   stateNc                     t          |                                          h dk    sJ |                                D ]\  }}t          | ||           dS )zReset the state of the registry>   r@   rC   rB   rA   rD   N)rU   rQ   itemssetattr)r   r[   keyvals       r   r1   zPluginRegistry._set_state   st    5::<<   %
 %
 %
 
 
 
 
  	$ 	$HCD#s####	$ 	$r   c                    | j         vr	 fdt          | j                  D             \  }nL# t          $ r?}| j        v rt          | j                           |t          | j                  |d }~ww xY wt          t          |                                          }| 	                    |           | _
        | j                  | _        t          |                                          t          | j                                                  z  D ]}|                    |          | j        |<    || _        d S )Nc                 *    g | ]}|j         k    |S r    rL   )rM   rN   r   s     r   rO   z*PluginRegistry._enable.<locals>.<listcomp>   s,       w$ &r   )rB   rR   r=   
ValueErrorentrypoint_err_messagesr   r	   r   loadrI   rA   r@   rU   rQ   rD   rG   rC   )r   r   r&   rN   errr.   r_   s    `     r   r)   zPluginRegistry._enable   sR   t}$$
R   4T5KLL  
  R R R4777$T%A$%GHHcQ*4+A4HHcQ	R
 RWWYY//EMM$&&& }T*w||~~&&T-B-G-G-I-I)J)JJ 	: 	:C)0S)9)9D!#&&s   "/ 
A8:A33A8c                 0    || j         }t          | |fi |S )a  Enable a plugin by name.

        This can be either called directly, or used as a context manager.

        Parameters
        ----------
        name : string (optional)
            The name of the plugin to enable. If not specified, then use the
            current active name.
        **options :
            Any additional parameters will be passed to the plugin as keyword
            arguments

        Returns
        -------
        PluginEnabler:
            An object that allows enable() to be used as a context manager
        )activer"   )r   r   r&   s      r   enablezPluginRegistry.enable   s(    & <;DT4337333r   c                     | j         S )z.Return the name of the currently active plugin)rA   r   s    r   rh   zPluginRegistry.active   s       r   c                     | j         S )z%Return the current options dictionary)rC   r   s    r   r&   zPluginRegistry.options   s     }r   c                 L    | j         rt          | j        fi | j         S | j        S )z#Return the currently active plugin.)rC   r   r@   r   s    r   getzPluginRegistry.get   s.    = 	 77777<r   c                     d                     | j        j        | j        t	          |                                                     S )Nz {}(active={!r}, registered={!r}))r4   r5   r   rA   rP   rY   r   s    r   r6   zPluginRegistry.__repr__   s9    4;;N#T%6TZZ\\8J8J
 
 	
r   r   )r   r   r   r7   rd   rD   objectr8   r9   r   r   r   rI   r   rY   r   r   r'   r1   r)   r"   ri   propertyrh   r&   rm   r6   r    r   r   r$   r$   5   s        $ ! 02 G G# G G G G G&S *)= (:BV    2!tCy ! ! ! !
DcN 
 
 
 

$S#X 
$4 
$ 
$ 
$ 
$ C  t        *4 48C= 4} 4 4 4 4. ! ! ! ! X! c3h    X Xj)        
# 
 
 
 
 
 
r   r$   c                     t                      }t          |d          r|                    |           S |                    | g           S )Nselect)r   )r   hasattrrr   rm   )r   rN   s     r   rR   rR      sG    	B
 r8 !yyuy%%%vveR   r   )systypingr   r   r   r   r   r   r	   typesr
   version_infoimportlib.metadatar   importlib_metadatatoolzr   r   r:   r   r"   r$   rR   r    r   r   <module>r{      sa   



 D D D D D D D D D D D D D D D D D D      v/////////////       W\""
M M M M My M M MU U U U U U U U8c
 c
 c
 c
 c
WZ( c
 c
 c
L	! 	! 	! 	! 	!r   