
    	Ae,                         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y)zA
Internal hook annotation, representation and calling machinery.
    Nc                        e Zd ZdZd Z	 ddZy)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                     || _         y Nproject_nameselfr   s     -lib/python3.12/site-packages/pluggy/_hooks.py__init__zHookspecMarker.__init__   
    (    Nc                 2      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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    K !JKK!!G+ +%!- Kr    )r
   functionr   r   r   r   s   ` ``` r   __call__zHookspecMarker.__call__   s!    "	 (22((r   )NFFN__name__
__module____qualname____doc__r   r   r   r   r   r   r   	   s    ) NR")r   r   c                   *    e Zd ZdZd Z	 	 	 	 	 	 ddZy)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                     || _         y r   r   r	   s     r   r   zHookimplMarker.__init__A   r   r   Nc                 :      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                 X    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   s:    !!G+ +!-%#%
 Kr   r   )r
   r   r(   r)   r*   r+   r,   r-   s   ` ````` r   r   zHookimplMarker.__call__D   s'    H	 	 (((22r   )NFFFFNr   r   r   r   r#   r#   9   s%    )
 53r   r#   c                     | j                  dd       | j                  dd       | j                  dd       | j                  dd       | j                  dd        y )Nr*   Fr+   r(   r)   r,   )
setdefault)optss    r   normalize_hookimpl_optsr1   |   sH    OOJ&OOIu%OOM5)OONE*OOJ%r   pypy_version_infoc                    t        j                  |       r	 | j                  } n#t        j                  |       s	 t        | d|       } 	 t        j                  |       }t        |j                        |j                  }}|r t        |       }|d| t        ||d       }}nd}t        sdnd}|r0t        j                  |       sdt        | dd      v r|d	   |v r|d
d }||fS # t        $ r Y yw xY w# t        $ r Y yw xY w# t        $ r Y yw xY w)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	==D t$	4T2D%%d+ 499%t}}(DXFU|U4<%8f ',YND!7444aN9R8D<;  		
  		
  s4   C" C1 D  "	C.-C.1	C=<C= 	DDc                       e Zd ZdZy)
_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                   X    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y)_HookCallerNc                     || _         g | _        g | _        || _        d | _        d | _        ||J | j                  ||       y y r   )name	_wrappers_nonwrappers	_hookexec_call_historyrF   set_specification)r
   rP   hook_executespecmodule_or_class	spec_optss        r   r   z_HookCaller.__init__   sS    	%!	*((""#6	B +r   c                     | j                   d uS r   )rF   r4   s    r   has_specz_HookCaller.has_spec   s    yy$$r   c                     | j                         rJ t        || j                  |      | _        |j	                  d      rg | _        y y )Nr   )rZ   HookSpecrP   rF   getrT   )r
   rW   rX   s      r   rU   z_HookCaller.set_specification   s<    ==?"0$))YG	==$!#D %r   c                     | j                   d uS r   )rT   r4   s    r   is_historicz_HookCaller.is_historic   s    !!--r   c                 x    fd} || j                         " || j                        t        dd      y y )Nc                 T    t        |       D ]  \  }}|j                  k(  s| |=  y y )NT)	enumerateplugin)wrappersimethodrc   s      r   removez*_HookCaller._remove_plugin.<locals>.remove   s1    &x0  	6==F*  r   zplugin z
 not found)rQ   rR   r   )r
   rc   rg   s    ` r   _remove_pluginz_HookCaller._remove_plugin   sH    	  $..!)d''(0 76*J!?@@ 1 *r   c                 4    | j                   | j                  z   S r   )rR   rQ   r4   s    r   get_hookimplsz_HookCaller.get_hookimpls   s      4>>11r   c                 j   |j                   r| j                  }n| j                  }|j                  r|j	                  d|       y|j
                  r|j                  |       yt        |      dz
  }|dk\  r)||   j
                  r|dz  }|dk\  r||   j
                  r|j	                  |dz   |       y)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    nnG''GNN1h'NN8$ Gq Aq&WQZ00Q q&WQZ00NN1q5(+r   c                 "    d| j                   dS )Nz<_HookCaller >)rP   r4   s    r   __repr__z_HookCaller.__repr__   s    tyym1--r   c                     |rt        d      | j                         rJ | j                  r| j                  j                  D ]g  }||vst	        t        | j                  j                        |j                         z
        }t        j                  dj                  |      d        n | j                  j                  j                  d      }nd}| j                  | j                  | 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    JKK##%% 9999-- &( %c$))*<*<&=&M NIMM==CVI=N#$
  ))..,,];KK~~dii););)=v{SSr   c                     | j                   j                  |xs i |f       | j                  | j                  | j	                         |d      }|y|xs g D ]
  } ||        y)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  sh     	!!6<R"AB nnTYY(:(:(<feL" 	AA	r   c                    t        | j                        t        | j                        f}|D ]/  }t        ddd      }t	        dd||      }| j                  |       1 	  | 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$$%tDNN';; 	)FE55IDh=Hx(	)	4>&>03-Dt~-Dt~s    A7 7Bc                     | j                         rE| j                  D ]5  \  }}| j                  | j                  |g|d      }|s(|+ ||d          7 yy)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[    +/+=+= ,'nnTYY&%H?6#CF+, r   )NN)r   r   r    r   rZ   rU   r_   rh   rj   rp   rs   r   r   r   r   r   r   r   rN   rN      sA    	C%$.	A2,$.T. 4,r   rN   c                       e Zd Zd Zd Zy)r   c                     || _         t        | j                         \  | _        | _        || _        || _        || _        | j                  j                  |       y r   )	r   rJ   rw   
kwargnamesrc   r0   plugin_name__dict__update)r
   rc   r   r   hook_impl_optss        r   r   zHookImpl.__init__2  sH     )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#    '(8(8';9T[[OSTUUr   N)r   r   r    r   rs   r   r   r   r   r   1  s    -Vr   r   c                       e Zd Zd Zy)r\   c                     || _         t        ||      x| _        }|| _        t	        |      \  | _        | _        || _        |j                  d      | _	        y )Nr   )
	namespacer<   r   rP   rJ   rw   r   r0   r]   r   )r
   r   rP   r0   r   s        r   r   zHookSpec.__init__?  sN    "#*9d#;;	)1();&t	 HH^4r   N)r   r   r    r   r   r   r   r\   r\   >  s    5r   r\   )r!   r8   sysrz   r   r#   r1   hasattrrD   rJ   rL   rN   r   r\   r   r   r   <module>r      st     
 -) -)`@3 @3F& 	()'T v, v,r
V 
V5 5r   