B
    `                 @   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   V/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/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 )N)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  }}y
| }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.
        N)r   r   )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   yt |  W n tk
r*   t| d Y nX t|}y| | 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.
    zdid not yieldzhas second yield)nextStopIterationr   r   r%   sendr+   )r   r#   Zcall_outcomer   r   r   _wrapped_callT   s    

r1   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   r3   kwargsr5   r   r   r   r   p   s    
z_LegacyMultiCall.__init__c                s   | j  g  | _}| j}x| jr| j }y fdd|jD }W n: tk
rz   x$|jD ]}| krXtd|f qXW Y nX |jrt	|j
| | jS |j
| }|d k	r|r|S || qW |s|S d S )Nc                s   g | ]} | qS r   r   ).0argname)r4   r   r   
<listcomp>~   s    z,_LegacyMultiCall.execute.<locals>.<listcomp>z"hook call must provide argument %r)r4   resultsr5   r3   popargnamesKeyErrorr   hookwrapperr1   functionexecuteappend)r   r:   r5   	hook_implargsr8   resr   )r4   r   r@   v   s*    


z_LegacyMultiCall.executec             C   s:   dt | jf }t| dr,dt | j | }d|| jf S )Nz%d methsr:   z%d results, z<_MultiCall %s, kwargs=%r>)lenr3   hasattrr:   r4   )r   statusr   r   r   __repr__   s    
z_LegacyMultiCall.__repr__N)F)r   r   r   r   r   r@   rH   r   r   r   r   r2   g   s   
r2   Fc             C   s   t | ||d S )N)r5   )r2   r@   )r3   r4   r5   r   r   r   _legacymulticall   s    rI   c                s  d}g }d}zg }yxt | D ]}y fdd|jD }W n: tk
rt   x$|jD ]}	|	 krRtd|	f qRW Y nX |jry |j| }
t|
 ||
 W q tk
r   t	|
d Y qX q|j| }|dk	r|| |rP qW W n t
k
r   t }Y nX W d|r*t|r |d nd|}n
t||}xBt |D ]6}
y|
| t	|
d W n tk
rp   Y nX q>W | S )	zExecute a call into multiple python functions/methods and return the
    result(s).

    ``caller_kwargs`` comes from _HookCaller.__call__().
    TNc                s   g | ]} | qS r   r   )r7   r8   )r4   r   r   r9      s    z_multicall.<locals>.<listcomp>z"hook call must provide argument %rzdid not yieldr   zhas second yield)reversedr<   r=   r   r>   r?   r.   rA   r/   r   r   r    r!   r   r0   r+   )r3   r4   r5   r$   r:   r   Z	teardownsrB   rC   r8   genrD   outcomer   )r4   r   
_multicall   sL    





rM   )F)F)r   r    r   version_infor(   execr   	Exceptionr   objectr   r1   r2   rI   rM   r   r   r   r   <module>   s   
50
