a
    ܌xd,                     @   s   d Z ddlZddlZddlZG dd dZG dd dZdd Zeed	Zd
d Z	G dd dZ
G dd dZG dd dZG dd dZdS )zA
Internal hook annotation, representation and calling machinery.
    Nc                   @   s"   e Zd ZdZdd Zd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                 C   s
   || _ d S Nproject_nameselfr    r   E/var/www/html/Ranjet/env/lib/python3.9/site-packages/pluggy/_hooks.py__init__   s    zHookspecMarker.__init__NFc                    s*    fdd}|dur"||S |S d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                    s0   r rt dt| jd t d | S )Nz'cannot have a historic firstresult hook_spec)firstresulthistoricwarn_on_impl)
ValueErrorsetattrr   dictfuncr   r   r   r   r   r	   setattr_hookspec_opts%   s    	z6HookspecMarker.__call__.<locals>.setattr_hookspec_optsNr   )r   functionr   r   r   r   r   r   r	   __call__   s    zHookspecMarker.__call__)NFFN__name__
__module____qualname____doc__r
   r   r   r   r   r	   r   	   s    r   c                   @   s"   e Zd ZdZdd Zd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                 C   s
   || _ d S r   r   r   r   r   r	   r
   A   s    zHookimplMarker.__init__NFc                    s.    fdd}|du r"|S ||S d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              
      s$   t | jd t d | S )N_impl)hookwrapperoptionalhooktryfirsttrylastspecname)r   r   r   r   r   r    r   r#   r!   r"   r   r	   setattr_hookimpl_optsh   s    z6HookimplMarker.__call__.<locals>.setattr_hookimpl_optsNr   )r   r   r   r    r!   r"   r#   r%   r   r$   r	   r   D   s    $zHookimplMarker.__call__)NFFFFNr   r   r   r   r	   r   9   s         r   c                 C   s@   |  dd |  dd |  dd |  dd |  dd  d S )Nr!   Fr"   r   r    r#   )
setdefault)optsr   r   r	   normalize_hookimpl_opts|   s
    r(   pypy_version_infoc                 C   s  t | r,z
| j} W q\ ty(   Y dS 0 n0t | s\zt| d| } W n tyZ   Y dS 0 zt | }W n ty~   Y dS 0 t	|j
|j }}|rt| }|d| t	||d  }}nd}tsdnd}|rt | 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   specr7   r8   indexkwargsZimplicit_namesr   r   r	   varnames   s8    




 
r?   c                   @   s   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   r	   r@      s   r@   c                   @   sp   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd Zdd Z	dd Z
dd ZdddZdd Zdd ZdS )_HookCallerNc                 C   sH   || _ g | _g | _|| _d | _d | _|d urD|d us8J | || d S r   )name	_wrappers_nonwrappers	_hookexec_call_historyr<   set_specification)r   rB   Zhook_executespecmodule_or_class	spec_optsr   r   r	   r
      s    z_HookCaller.__init__c                 C   s
   | j d uS r   )r<   r*   r   r   r	   has_spec   s    z_HookCaller.has_specc                 C   s0   |   rJ t|| j|| _|dr,g | _d S )Nr   )rJ   HookSpecrB   r<   getrF   )r   rH   rI   r   r   r	   rG      s    
z_HookCaller.set_specificationc                 C   s
   | j d uS r   )rF   r*   r   r   r	   is_historic   s    z_HookCaller.is_historicc                    s<    fdd}|| j d u r8|| jd u r8td dd S )Nc                    s,   t | D ]\}}|j kr| |=  dS qd S )NT)	enumerateplugin)ZwrappersimethodrO   r   r	   remove   s    
z*_HookCaller._remove_plugin.<locals>.removezplugin z
 not found)rC   rD   r   )r   rO   rS   r   rR   r	   _remove_plugin   s    z_HookCaller._remove_pluginc                 C   s   | j | j S r   )rD   rC   r*   r   r   r	   get_hookimpls   s    z_HookCaller.get_hookimplsc                 C   sv   |j r| j}n| j}|jr(|d| nJ|jr:|| n8t|d }|dkrb|| jrb|d8 }qF||d | dS )z,Add an implementation to the callback chain.r   r-   N)r   rC   rD   r"   insertr!   appendr9   )r   hookimplmethodsrP   r   r   r	   _add_hookimpl   s    
z_HookCaller._add_hookimplc                 C   s   d| j dS )Nz<_HookCaller >)rB   r*   r   r   r	   __repr__   s    z_HookCaller.__repr__c                 O   s   |rt d|  rJ | jrt| jjD ]<}||vr&tt| jj|  }tjd	|dd  qdq&| 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)r5   rM   r<   argnamesr6   setkeyswarningswarnformatr'   rL   rE   rB   rU   )r   r7   r>   argnameZ	notincallr   r   r   r	   r      s"    z_HookCaller.__call__c                 C   sP   | j |pi |f | | j|  |d}|du r6dS |p<g D ]}|| q>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)rF   rW   rE   rB   rU   )r   result_callbackr>   resxr   r   r	   call_historic  s    z_HookCaller.call_historicc              	   C   st   t | jt | jf}|D ]*}tdddd}tdd||}| | qz| f i |W |\| _| _S |\| _| _0 dS )zCall the hook with some additional temporarily participating
        methods using the specified ``kwargs`` as call parameters.F)r   r"   r!   Nz<temp>)listrD   rC   r   HookImplrZ   )r   rY   r>   oldrQ   r'   rX   r   r   r	   
call_extra  s    z_HookCaller.call_extrac                 C   sH   |   rD| jD ]4\}}| | j|g|d}|r|dur||d  qdS )zAApply call history to a new hookimpl if it is marked as historic.FNr   )rM   rF   rE   rB   )r   rQ   r>   rf   rg   r   r   r	   _maybe_apply_history(  s
    z _HookCaller._maybe_apply_history)NN)NN)r   r   r   r
   rJ   rG   rM   rT   rU   rZ   r\   r   ri   rm   rn   r   r   r   r	   rA      s   

rA   c                   @   s   e Zd Zdd Zdd ZdS )rk   c                 C   s:   || _ t| j \| _| _|| _|| _|| _| j| d S r   )	r   r?   r_   
kwargnamesrO   r'   plugin_name__dict__update)r   rO   rp   r   Zhook_impl_optsr   r   r	   r
   2  s    zHookImpl.__init__c                 C   s   d| j d| jdS )Nz<HookImpl plugin_name=z	, plugin=r[   )rp   rO   r*   r   r   r	   r\   :  s    zHookImpl.__repr__N)r   r   r   r
   r\   r   r   r   r	   rk   1  s   rk   c                   @   s   e Zd Zdd ZdS )rK   c                 C   sB   || _ t|| | _}|| _t|\| _| _|| _|d| _	d S )Nr   )
	namespacer2   r   rB   r?   r_   ro   r'   rL   r   )r   rs   rB   r'   r   r   r   r	   r
   ?  s    zHookSpec.__init__N)r   r   r   r
   r   r   r   r	   rK   >  s   rK   )r   r.   sysrb   r   r   r(   hasattrr:   r?   r@   rA   rk   rK   r   r   r   r	   <module>   s   0C
*y