
    0Ic,                         d Z ddlZddlZddlZ G d d          Z G d d          Zd Z eed          Zd	 Z	 G d
 d          Z
 G d d          Z G d d          Z G d d          ZdS )zA
Internal hook annotation, representation and calling machinery.
    Nc                   "    e Zd ZdZd Z	 ddZdS )HookspecMarkera,  Decorator helper class for marking functions as hook specifications.

    You can instantiate it with a project_name to get a decorator.
    Calling :py:meth:`.PluginManager.add_hookspecs` later will discover all marked functions
    if the :py:class:`.PluginManager` uses the same project_name.
    c                     || _         d S Nproject_nameselfr   s     -lib/python3.11/site-packages/pluggy/_hooks.py__init__zHookspecMarker.__init__       (    NFc                 8      fd}| ||          S |S )ak  if passed a function, directly sets attributes on the function
        which will make it discoverable to :py:meth:`.PluginManager.add_hookspecs`.
        If passed no function, returns a decorator which can be applied to a function
        later using the attributes supplied.

        If ``firstresult`` is ``True`` the 1:N hook call (N being the number of registered
        hook implementation functions) will stop at I<=N when the I'th function
        returns a non-``None`` result.

        If ``historic`` is ``True`` calls to a hook will be memorized and replayed
        on later registered plugins.

        c           	          rrt          d          t          | j        dz   t                               | S )Nz'cannot have a historic firstresult hook_spec)firstresulthistoricwarn_on_impl)
ValueErrorsetattrr   dict)funcr   r   r
   r   s    r   setattr_hookspec_optsz6HookspecMarker.__call__.<locals>.setattr_hookspec_opts%   se     LK L !JKKK!G+ +%!-     Kr    )r
   functionr   r   r   r   s   ` ``` r   __call__zHookspecMarker.__call__   sO    "	 	 	 	 	 	 	 	  	)((222((r   )NFFN__name__
__module____qualname____doc__r   r   r   r   r   r   r   	   sH         ) ) ) NR") ") ") ") ") ")r   r   c                   ,    e Zd ZdZd Z	 	 	 	 	 	 ddZdS )HookimplMarkera)  Decorator helper class for marking functions as hook implementations.

    You can instantiate with a ``project_name`` to get a decorator.
    Calling :py:meth:`.PluginManager.register` later will discover all marked functions
    if the :py:class:`.PluginManager` uses the same project_name.
    c                     || _         d S r   r   r	   s     r   r   zHookimplMarker.__init__A   r   r   NFc                 @      fd}||S  ||          S )a~  if passed a function, directly sets attributes on the function
        which will make it discoverable to :py:meth:`.PluginManager.register`.
        If passed no function, returns a decorator which can be applied to a
        function later using the attributes supplied.

        If ``optionalhook`` is ``True`` a missing matching hook specification will not result
        in an error (by default it is an error if no matching spec is found).

        If ``tryfirst`` is ``True`` this hook implementation will run as early as possible
        in the chain of N hook implementations for a specification.

        If ``trylast`` is ``True`` this hook implementation will run as late as possible
        in the chain of N hook implementations.

        If ``hookwrapper`` is ``True`` the hook implementations needs to execute exactly
        one ``yield``.  The code before the ``yield`` is run early before any non-hookwrapper
        function is run.  The code after the ``yield`` is run after all non-hookwrapper
        function have run.  The ``yield`` receives a :py:class:`.callers._Result` object
        representing the exception or result outcome of the inner calls (including other
        hookwrapper calls).

        If ``specname`` is provided, it will be used instead of the function name when
        matching this hook implementation to a hook specification during registration.

        c                 ^    t          | j        dz   t                               | S )N_impl)hookwrapperoptionalhooktryfirsttrylastspecname)r   r   r   )r   r(   r)   r
   r,   r*   r+   s    r   setattr_hookimpl_optsz6HookimplMarker.__call__.<locals>.setattr_hookimpl_optsh   sK    !G+ +!-%#%  
 
 
 Kr   r   )r
   r   r(   r)   r*   r+   r,   r-   s   ` ````` r   r   zHookimplMarker.__call__D   s\    H	 	 	 	 	 	 	 	 	 	  	3((((222r   )NFFFFNr   r   r   r   r#   r#   9   sU         ) ) )
 53 53 53 53 53 53r   r#   c                     |                      dd           |                      dd           |                      dd           |                      dd           |                      dd            d S )Nr*   Fr+   r(   r)   r,   )
setdefault)optss    r   normalize_hookimpl_optsr1   |   sl    OOJ&&&OOIu%%%OOM5)))OONE***OOJ%%%%%r   pypy_version_infoc                 V   t          j        |           r	 | j        } nI# t          $ r Y dS w xY wt          j        |           s$	 t          | d|           } n# t          $ r Y dS w xY w	 t          j        |           }n# t          $ r Y dS w xY wt          |j
                  |j        }}|r2t          |           }|d|         t          ||d                   }}nd}t          sdnd}|r;t          j        |           sdt          | dd          v r|d	         |v r
|d
d         }||fS )zReturn tuple of positional and keywrord argument names for a function,
    method, class or callable.

    In case of a class, its ``__init__`` method is considered.
    For methods the ``self`` parameter is not included.
    )r   r   r   Nr   r
   )r
   obj.r    r      )inspectisclassr   AttributeError	isroutinegetattr	Exceptiongetfullargspec	TypeErrortupleargsdefaultslen_PYPYismethod)r   specrA   rB   indexkwargsimplicit_namess          r   varnamesrJ      s    t 		=DD 	 	 	66	t$$ 	4T22DD 	 	 	66	%d++   vv 49%%t}(D XFUF|U4<%8%8f ',@YYN D!! 	74444	9=aN9R	 8D<s0    
,,A 
A$#A$(A= =
B
Bc                       e Zd ZdZdS )
_HookRelayzghook holder object for performing 1:N hook calls where N is the number
    of registered plugins.

    N)r   r   r    r!   r   r   r   rL   rL      s           r   rL   c                   Z    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 ZddZd Zd ZdS )_HookCallerNc                     || _         g | _        g | _        || _        d | _        d | _        ||J |                     ||           d S d S r   )name	_wrappers_nonwrappers	_hookexec_call_historyrF   set_specification)r
   rP   hook_executespecmodule_or_class	spec_optss        r   r   z_HookCaller.__init__   sl    	%!	 	C(((""#6	BBBBB	C 	Cr   c                     | j         d uS r   )rF   r4   s    r   has_specz_HookCaller.has_spec   s    y$$r   c                     |                                  rJ t          || j        |          | _        |                    d          r	g | _        d S d S )Nr   )rZ   HookSpecrP   rF   getrT   )r
   rW   rX   s      r   rU   z_HookCaller.set_specification   sX    ==??"""0$)YGG	==$$ 	$!#D	$ 	$r   c                     | j         d uS r   )rT   r4   s    r   is_historicz_HookCaller.is_historic   s    !--r   c                 |    fd} || j                   # || j                  t          dd          d S d S )Nc                 T    t          |           D ]\  }}|j        k    r| |=  dS d S )NT)	enumerateplugin)wrappersimethodrc   s      r   removez*_HookCaller._remove_plugin.<locals>.remove   sJ    &x00    	6=F*   44    r   zplugin z
 not found)rQ   rR   r   )r
   rc   rg   s    ` r   _remove_pluginz_HookCaller._remove_plugin   s{    	  	  	  	  	  6$.!! 	Avd'(( A !?6!?!?!?@@@	A 	AA Ar   c                      | j         | j        z   S r   )rR   rQ   r4   s    r   get_hookimplsz_HookCaller.get_hookimpls   s     4>11r   c                 X   |j         r| j        }n| j        }|j        r|                    d|           dS |j        r|                    |           dS t          |          dz
  }|dk    r%||         j        r|dz  }|dk    r||         j        |                    |dz   |           dS )z,Add an implementation to the callback chain.r   r7   N)r(   rQ   rR   r+   insertr*   appendrC   )r
   hookimplmethodsre   s       r   _add_hookimplz_HookCaller._add_hookimpl   s     	(nGG'G 		,NN1h''''' 	,NN8$$$$$ Gq Aq& WQZ0 Q q& WQZ0 NN1q5(+++++r   c                     d| j         dS )Nz<_HookCaller >)rP   r4   s    r   __repr__z_HookCaller.__repr__   s    -ty----r   c                    |rt          d          |                                 rJ | j        r| j        j        D ]l}||vrft	          t          | j        j                  |                                z
            }t          j        d	                    |          d            nm| j        j
                            d          }nd}|                     | j        |                                 ||          S )Nz,hook calling supports only keyword argumentszTArgument(s) {} which are declared in the hookspec can not be found in this hook call   )
stacklevelr   F)r?   r_   rF   argnamesr@   setkeyswarningswarnformatr0   r]   rS   rP   rj   )r
   rA   rH   argname	notincallr   s         r   r   z_HookCaller.__call__   s    	LJKKK##%%%%% 9 	 9-  &(  %c$)*<&=&=&M N NIM==CVI=N=N#$   
 E ).,,];;KKK~~di););)=)=v{SSSr   c                     | j                             |pi |f           |                     | j        |                                 |d          }|dS |pg D ]} ||           dS )a  Call the hook with given ``kwargs`` for all registered plugins and
        for all plugins which will be registered afterwards.

        If ``result_callback`` is not ``None`` it will be called for for each
        non-``None`` result obtained from a hook implementation.
        FN)rT   rm   rS   rP   rj   )r
   result_callbackrH   resxs        r   call_historicz_HookCaller.call_historic  s     	!!6<R"ABBB nnTY(:(:(<(<feLL 	F 	 	AOA	 	r   c                 &   t          | j                  t          | j                  f}|D ];}t          ddd          }t	          dd||          }|                     |           <	  | di ||\  | _        | _        S # |\  | _        | _        w xY w)zCall the hook with some additional temporarily participating
        methods using the specified ``kwargs`` as call parameters.F)r(   r+   r*   Nz<temp>r   )listrR   rQ   r   HookImplrp   )r
   ro   rH   oldrf   r0   rn   s          r   
call_extraz_HookCaller.call_extra  s     4$%%tDN';';; 	) 	)FE55IIIDh==Hx((((	44>>&>>03-Dt~~-Dt~3333s   (A? ?Bc                     |                                  r@| j        D ]:\  }}|                     | j        |g|d          }|r| ||d                    9dS dS )zAApply call history to a new hookimpl if it is marked as historic.FNr   )r_   rT   rS   rP   )r
   rf   rH   r   r   s        r   _maybe_apply_historyz _HookCaller._maybe_apply_history(  s     	,+/+= , ,'nnTY&%HH ,? ,#OCF+++		, 	,, ,r   )NN)r   r   r    r   rZ   rU   r_   rh   rj   rp   rs   r   r   r   r   r   r   r   rN   rN      s        	C 	C 	C 	C% % %$ $ $. . .	A 	A 	A2 2 2, , ,$. . .T T T.    4 4 4, , , , ,r   rN   c                       e Zd Zd Zd ZdS )r   c                     || _         t          | j                   \  | _        | _        || _        || _        || _        | j                            |           d S r   )	r   rJ   rw   
kwargnamesrc   r0   plugin_name__dict__update)r
   rc   r   r   hook_impl_optss        r   r   zHookImpl.__init__2  sS     )1$-)@)@&t"	&^,,,,,r   c                 (    d| j         d| j        dS )Nz<HookImpl plugin_name=z	, plugin=rr   )r   rc   r4   s    r   rs   zHookImpl.__repr__:  s     U(8UUT[UUUUr   N)r   r   r    r   rs   r   r   r   r   r   1  s7        - - -V V V V Vr   r   c                       e Zd Zd ZdS )r\   c                     || _         t          ||          x| _        }|| _        t	          |          \  | _        | _        || _        |                    d          | _	        d S )Nr   )
	namespacer<   r   rP   rJ   rw   r   r0   r]   r   )r
   r   rP   r0   r   s        r   r   zHookSpec.__init__?  s]    "#*9d#;#;;	)1(););&t	 HH^44r   N)r   r   r    r   r   r   r   r\   r\   >  s#        5 5 5 5 5r   r\   )r!   r8   sysrz   r   r#   r1   hasattrrD   rJ   rL   rN   r   r\   r   r   r   <module>r      st     



 -) -) -) -) -) -) -) -)`@3 @3 @3 @3 @3 @3 @3 @3F& & & 	())' ' 'T       v, v, v, v, v, v, v, v,r
V 
V 
V 
V 
V 
V 
V 
V5 5 5 5 5 5 5 5 5 5r   