
    ȯei<'                       d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	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 ej"                  d
k\  rd dl	mZ nd dlmZ e
rd dlmZ  ed      Z ed      Z ededef   ef      Z edee         Zeegeee      f   ZddZ G d de      Z G d deeef         Z  G d deeef         Z!d Z"y)    )annotationsN)Callable)partial)entry_points)TYPE_CHECKINGAnyGenericTypeVarcast)deprecated_warn)      )TypeIs)r      )TypeAliasType)TracebackTypeTRPlugin.)type_paramsPluginT)boundc                    d fd}|S )zq
    Converts a type to guard function.

    Added for compatibility with original `PluginRegistry` default.
    c                   t        |       S N)
isinstance)objtps    ^/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/altair/utils/plugin_registry.pyfuncz_is_type.<locals>.func%   s    #r""    )r   objectreturnzTypeIs[type[T]] )r   r    s   ` r   _is_typer%      s    # Kr!   c                      e Zd Zd Zd Zy)NoSuchEntryPointc                     || _         || _        y r   )groupname)selfr)   r*   s      r   __init__zNoSuchEntryPoint.__init__,   s    
	r!   c                :    d| j                   d| j                  S )NzNo z entry point found in group )r*   r)   r+   s    r   __str__zNoSuchEntryPoint.__str__0   s    TYYM!=djj^LLr!   N)__name__
__module____qualname__r,   r/   r$   r!   r   r'   r'   +   s    Mr!   r'   c                  @    e Zd ZdZ	 	 	 	 	 	 	 	 ddZddZd	dZd
dZy)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
    c                    || _         || _        || _        |j                         | _         | j                   j
                  |fi | y r   )registryr*   options
_get_stateoriginal_state_enable)r+   r6   r*   r7   s       r   r,   zPluginEnabler.__init__@   sC     5=	'..6.A.A.Cd.g.r!   c                    | S r   r$   r.   s    r   	__enter__zPluginEnabler.__enter__I   s    r!   c                N    | j                   j                  | j                         y r   )r6   
_set_stater9   )r+   typvalue	tracebacks       r   __exit__zPluginEnabler.__exit__L   s      !4!45r!   c                `    t        | j                        j                   d| j                  dS )Nz.enable())typer6   r0   r*   r.   s    r   __repr__zPluginEnabler.__repr__O   s)    t}}%../x		}AFFr!   N)r6   zPluginRegistry[PluginT, R]r*   strr7   r   r#   None)r#   PluginEnabler[PluginT, R])r?   rE   r@   	ExceptionrA   r   r#   rH   r#   rG   )r0   r1   r2   __doc__r,   r<   rB   rF   r$   r!   r   r4   r4   4   s<    	/2/:=/JM/	/6Gr!   r4   c                      e Zd ZU dZi Zded<   i Zded<   def	 	 	 	 	 ddZddZ	dd	Z
dd
ZddZddZ	 d	 	 	 	 	 ddZedd       Zedd       ZddZddZy)PluginRegistrya  
    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")

    zdict[str, str]entrypoint_err_messagesdict[str, Any]_global_settings c                `   || _         |  |t        urQt        |t              rAdt        |       j                  d}t        |d       t        dt        |            | _        n|| _        d| _	        d| _
        i | _        i | _        | j                  j                  j                         | _        y)a  
        Create a PluginRegistry for a named entry point group.

        Parameters
        ----------
        entry_point_group: str
            The name of the entry point group.
        plugin_type
            A type narrowing function that will optionally be used for runtime
            type checking loaded plugins.

        References
        ----------
        https://typing.readthedocs.io/en/latest/spec/narrowing.html
        z<Pass a callable `TypeIs` function to `plugin_type` instead.
z~(plugin_type)

See also:
https://typing.readthedocs.io/en/latest/spec/narrowing.html
https://docs.astral.sh/ruff/rules/assert/z5.4.0)versionIsPluginNrR   )entry_point_groupcallabler   rE   r0   r   r   r%   plugin_type_active_active_name_plugins_options	__class__rQ   copy)r+   rV   rX   msgs       r   r,   zPluginRegistry.__init__m   s    $ '8h&:k4+HO:&&) *<=  C1#J0EFD*D)-!#,.(*040O0O0T0T0Vr!   c                    || j                   j                  |d      S | j                  |      r|| j                   |<   |S t        |      j                  dt        |       j                  }t        |      )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.
        Nz is not compatible with )r[   poprX   rE   r0   	TypeError)r+   r*   r@   r_   s       r   registerzPluginRegistry.register   sr    & ===$$T400e$"'DMM$L%[)),,DT$ZEXEXD[\CC. r!   c                    t        | j                  j                               }t        | j                        }|D cg c]  }|j
                   }}|j                  |       t        t        |            S c c}w )z:List the names of the registered and entry points plugins.)	listr[   keysimportlib_metadata_getrV   r*   extendsortedset)r+   extse_pointsep	more_extss        r   nameszPluginRegistry.names   s`    DMM&&())$*@*@A'/0RWW0	0Ic$i   1s   A7c                    | j                   | j                  | j                  j                         | j                  j                         | j
                  j                         dS )zCReturn a dictionary representing the current state of the registry.)rY   rZ   r[   r\   rQ   )rY   rZ   r[   r^   r\   rQ   r.   s    r   r8   zPluginRegistry._get_state   sP     || --**,**, $ 5 5 : : <
 	
r!   c                    t        |j                               h dk(  sJ |j                         D ]  \  }}t        | ||        y)z Reset the state of the registry.>   rY   r\   r[   rZ   rQ   N)rj   rf   itemssetattr)r+   statekeyvals       r   r>   zPluginRegistry._set_state   sK    5::<  %
 
 	
 
  	$HCD#s#	$r!   c                ^   | j                   vrM	 fdt        | j                        D        \  }t        d|j                               }| j                  |       | _	        | j                      | _
        t        |j                               t        | j                  j                               z  D ]   }|j                  |      | j                  |<   " || _        y # t        $ rC}| j                  v rt        | j                           |t        | j                        |d }~ww xY w)Nc              3  @   K   | ]  }|j                   k(  r|  y wr   )r*   ).0rm   r*   s     r   	<genexpr>z)PluginRegistry._enable.<locals>.<genexpr>   s$      ww$ s   r   )r[   rg   rV   
ValueErrorrO   r'   r   loadrc   rZ   rY   rj   rf   rQ   ra   r\   )r+   r*   r7   rm   errr@   ru   s    `     r   r:   zPluginRegistry._enable   s   t}}$
R4T5K5KL BGGI.EMM$& }}T*w||~&T-B-B-G-G-I)JJ 	:C)0S)9D!!#&	:  R4777$T%A%A$%GHcQ*4+A+A4HcQ	Rs    C   	D,)>D''D,Nc                8    || 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
        )activer4   )r+   r*   r7   s      r   enablezPluginRegistry.enable   s$    , <;;DT43733r!   c                    | j                   S )z/Return the name of the currently active plugin.)rZ   r.   s    r   r   zPluginRegistry.active   s        r!   c                    | j                   S )z&Return the current options dictionary.)r\   r.   s    r   r7   zPluginRegistry.options  s     }}r!   c                @   | j                   x}r5| j                  |      r$| j                  rt        |fi | j                  S |S | j                   Ct	        |       j
                  dt	        | j                         j
                  d}t        |      t        rt        y)z#Return the currently active plugin.Nz2 requires all plugins to be callable objects, but z is not callable.)	rY   rX   r\   r   rE   r0   rb   r   NotImplementedError)r+   r    r_   s      r   getzPluginRegistry.get  s    LL D d&6&6t&<59]]7414==1LL\\%:&&) *DLL)2255FH  C.  &%	 r!   c                n    t        |       j                   d| j                  d| j                         dS )Nz(active=z, registered=rD   )rE   r0   r   ro   r.   s    r   rF   zPluginRegistry.__repr__  s2    t*%%&ht{{o]4::<JZZ[\\r!   )rV   rG   rX   rU   r#   rH   )r*   rG   r@   PluginT | Noner#   r   )r#   z	list[str])r#   rP   )rt   rP   r#   rH   )r*   rG   r#   rH   r   )r*   z
str | Noner7   r   r#   rI   rK   )r#   zpartial[R] | Plugin[R] | None)r0   r1   r2   rL   rO   __annotations__rQ   rW   r,   rc   ro   r8   r>   r:   r   propertyr   r7   r   rF   r$   r!   r   rN   rN   S   s    & /1^0 (*n) (*8$W!$$W8@$W	$WL!8!

$ , "&44254	"44 ! !  & ]r!   rN   c                v    t               }t        |d      r|j                  |       S |j                  | g       S )Nselect)r)   )r   hasattrr   r   )r)   rm   s     r   rg   rg     s7    	B
 r8yyuy%%vveR  r!   )r   ztype[T]r#   z#Callable[[object], TypeIs[type[T]]])#
__future__r   syscollections.abcr   	functoolsr   importlib.metadatar   typingr   r   r	   r
   r   altair.utils.deprecationr   version_infor   typing_extensionsr   typesr   r   r   r   r   r"   rU   r%   rJ   r'   r4   rN   rg   r$   r!   r   <module>r      s    " 
 $  + = = 4w(w$/#CLCL	x#q&!1t	D
)6#;
/VHfVC[112
My MGGGQJ' G>D]WWaZ( D]N	!r!   