U
    Ha                     @   s   d Z ddlZddlZejdkZes*ed dd ZG dd deZG d	d
 d
e	Z
dd ZG dd de	ZdddZdddZdS )z
Call loop machinery
    N)   r   z4
def _reraise(cls, val, tb):
    raise cls, val, tb
c                 C   s$   | j }td|j|j|j|f d S )Nzwrap_controller at %r %s:%d %s)gi_codeRuntimeErrorco_nameco_filenameco_firstlineno)wrap_controllermsgco r   2/tmp/pip-unpacked-wheel-xuf3ljf8/pluggy/callers.py_raise_wrapfail   s    r   c                   @   s   e Zd ZdZdS )HookCallErrorz Hook was called wrongly. N)__name__
__module____qualname____doc__r   r   r   r   r      s   r   c                   @   sH   e Zd Zdd Zedd Zedd Zedd Zd	d
 Z	dd Z
dS )_Resultc                 C   s   || _ || _d S N_result_excinfo)selfresultexcinfor   r   r   __init__    s    z_Result.__init__c                 C   s   | j S r   )r   )r   r   r   r   r   $   s    z_Result.excinfoc                 C   s   d}t jt|dd | jS )zOGet the result(s) for this hook call (DEPRECATED in favor of ``get_result()``).z8Use get_result() which forces correct exception handling   )
stacklevel)warningswarnDeprecationWarningr   )r   r	   r   r   r   r   (   s    z_Result.resultc                 C   s>   d}d  }}z
| }W n t k
r2   t }Y nX | ||S )NT)BaseExceptionsysexc_info)clsfunc__tracebackhide__r   r   r   r   r   	from_call/   s    
z_Result.from_callc                 C   s   || _ d| _dS )zForce the result(s) to ``result``.

        If the hook was marked as a ``firstresult`` a single value should
        be set otherwise set a (modified) list of results. Any exceptions
        found during invocation will be deleted.
        Nr   )r   r   r   r   r   force_result:   s    z_Result.force_resultc                 C   s<   d}| j dkr| jS | j }tr0|d |d t|  dS )zGet the result(s) for this hook call.

        If the hook was marked as a ``firstresult`` only a single value
        will be returned otherwise a list of results.
        TN   r   )r   r   _py3with_tracebackZ_reraise)r   r&   exr   r   r   
get_resultD   s    
z_Result.get_resultN)r   r   r   r   propertyr   r   classmethodr'   r(   r-   r   r   r   r   r      s   




r   c                 C   sl   zt |  W n tk
r*   t| d Y nX t|}z| | t| d W n tk
rb   Y nX | S )a/   Wrap calling to a function with a generator which needs to yield
    exactly once.  The yield point will trigger calling the wrapped function
    and return its ``_Result`` to the yield point.  The generator then needs
    to finish (raise StopIteration) in order for the wrapped call to complete.
    did not yieldhas second yield)nextStopIterationr   r   r'   sendr-   )r   r%   Zcall_outcomer   r   r   _wrapped_callT   s    

r5   c                   @   s*   e Zd ZdZd
ddZdd Zdd Zd	S )_LegacyMultiCallz8 execute a call into multiple python functions/methods. Fc                 C   s    || _ || _| | jd< || _d S )NZ__multicall__
hook_implscaller_kwargsfirstresult)r   r8   kwargsr:   r   r   r   r   p   s    
z_LegacyMultiCall.__init__c                    s   | j  g  | _}| j}| jr| j }z fdd|jD }W n6 tk
rt   |jD ]}| krTtd|f qTY nX |jrt	|j
| | jS |j
| }|d k	r|r|S || q|s|S d S )Nc                    s   g | ]} | qS r   r   .0argnamer9   r   r   
<listcomp>~   s     z,_LegacyMultiCall.execute.<locals>.<listcomp>"hook call must provide argument %r)r9   resultsr:   r8   popargnamesKeyErrorr   hookwrapperr5   functionexecuteappend)r   rB   r:   	hook_implargsr>   resr   r?   r   rH   v   s,    



z_LegacyMultiCall.executec                 C   s:   dt | jf }t| dr,dt | j | }d|| jf S )Nz%d methsrB   z%d results, z<_MultiCall %s, kwargs=%r>)lenr8   hasattrrB   r9   )r   statusr   r   r   __repr__   s    
z_LegacyMultiCall.__repr__N)F)r   r   r   r   r   rH   rP   r   r   r   r   r6   g   s   
r6   Fc                 C   s   t | ||d S )N)r:   )r6   rH   r7   r   r   r   _legacymulticall   s
      rQ   c                    s  d}g }d}dzg }zt| D ]}	z fdd|	jD }
W n6 tk
rp   |	jD ]}| krPtd|f qPY nX |	j	rz |	j
|
 }t| || W q tk
r   t|d Y qX q|	j
|
 }|dk	r|| |r qqW n tk
r   t }Y nX W 5 |r$t |r|d nd|}n
t ||}t|D ]6}z|| t|d W n tk
rh   Y nX q6|   S X  )	zExecute a call into multiple python functions/methods and return the
    result(s).

    ``caller_kwargs`` comes from _HookCaller.__call__().
    TNr   r1   c                    s   g | ]} | qS r   r   r<   r?   r   r   r@      s     z_multicall.<locals>.<listcomp>rA   r0   )r   reversedr4   r   r3   r-   rD   rE   r   rF   rG   r2   rI   r!   r"   r#   )r8   r9   r:   r&   rB   r   ZoutcomeZ	teardownsgenrJ   rK   r>   rL   r   r?   r   
_multicall   sN    







rT   )F)F)r   r"   r   version_infor*   execr   	Exceptionr   objectr   r5   r6   rQ   rT   r   r   r   r   <module>   s   
50
