ó
—‰]c           @   s®   d  Z  d d l Z d d l Z e j d k Z e s> d d Un  d „  Z d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ	 d „  Z
 d e f d „  ƒ  YZ e d „ Z e d „ Z d S(   s   
Call loop machinery
iÿÿÿÿNi   i    s4   
def _reraise(cls, val, tb):
    raise cls, val, tb
c         C   s2   |  j  } t d | j | j | j | f ƒ ‚ d  S(   Ns   wrap_controller at %r %s:%d %s(   t   gi_codet   RuntimeErrort   co_namet   co_filenamet   co_firstlineno(   t   wrap_controllert   msgt   co(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   _raise_wrapfail   s    	t   HookCallErrorc           B   s   e  Z d  Z RS(   s    Hook was called wrongly. (   t   __name__t
   __module__t   __doc__(    (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR	      s   t   _Resultc           B   sP   e  Z d  „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z	 RS(   c         C   s   | |  _  | |  _ d  S(   N(   t   _resultt   _excinfo(   t   selft   resultt   excinfo(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   __init__    s    	c         C   s   |  j  S(   N(   R   (   R   (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR   $   s    c         C   s&   d } t  j t | ƒ d d ƒ|  j S(   sO   Get the result(s) for this hook call (DEPRECATED in favor of ``get_result()``).s8   Use get_result() which forces correct exception handlingt
   stackleveli   (   t   warningst   warnt   DeprecationWarningR   (   R   R   (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR   (   s    c         C   sJ   t  } d  } } y | ƒ  } Wn t k
 r< t j ƒ  } n X|  | | ƒ S(   N(   t   Truet   Nonet   BaseExceptiont   syst   exc_info(   t   clst   funct   __tracebackhide__R   R   (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt	   from_call/   s    
c         C   s   | |  _  d |  _ d S(   sñ   Force 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   (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   force_result:   s    	c         C   sS   t  } |  j d k r |  j S|  j } t rE | d j | d ƒ ‚ n  t | Œ  d S(   s­   Get 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.
        i   i   N(   R   R   R   R   t   _py3t   with_tracebackt   _reraise(   R   R   t   ex(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt
   get_resultD   s    	(
   R
   R   R   t   propertyR   R   t   classmethodR    R!   R&   (    (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR      s   		
c         C   sz   y t  |  ƒ Wn t k
 r. t |  d ƒ n Xt j | ƒ } y |  j | ƒ t |  d ƒ Wn t k
 ro n X| j ƒ  S(   s/   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.
    s   did not yields   has second yield(   t   nextt   StopIterationR   R   R    t   sendR&   (   R   R   t   call_outcome(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   _wrapped_callT   s    t   _LegacyMultiCallc           B   s,   e  Z d  Z e d „ Z d „  Z d „  Z RS(   s8    execute a call into multiple python functions/methods. c         C   s,   | |  _  | |  _ |  |  j d <| |  _ d  S(   Nt   __multicall__(   t
   hook_implst   caller_kwargst   firstresult(   R   R0   t   kwargsR2   (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR   p   s    		c         C   s  |  j  } g  |  _ } |  j } xá |  j r|  j j ƒ  } y$ g  | j D] } | | ^ qG } WnG t k
 r§ x7 | j D]( } | | k rx t d | f ƒ ‚ qx qx Wn X| j rÊ t	 | j
 | Œ  |  j ƒ S| j
 | Œ  } | d  k	 r" | rï | S| j | ƒ q" q" W| s| Sd  S(   Ns"   hook call must provide argument %r(   R1   t   resultsR2   R0   t   popt   argnamest   KeyErrorR	   t   hookwrapperR-   t   functiont   executeR   t   append(   R   R1   R4   R2   t	   hook_implt   argnamet   argst   res(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR:   v   s*    		$	c         C   sP   d t  |  j ƒ f } t |  d ƒ r? d t  |  j ƒ | } n  d | |  j f S(   Ns   %d methsR4   s   %d results, s   <_MultiCall %s, kwargs=%r>(   t   lenR0   t   hasattrR4   R1   (   R   t   status(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   __repr__   s    (   R
   R   R   t   FalseR   R:   RC   (    (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyR.   g   s   	c         C   s   t  |  | d | ƒj ƒ  S(   NR2   (   R.   R:   (   R0   R1   R2   (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   _legacymulticall—   s    c      	   C   sß  t  } g  } t } z?g  } yxt |  ƒ D] } y$ g  | j D] } | | ^ q> }	 WnG t k
 rž x3 | j D]( } | | k r— t d | f ƒ ‚ n  qo Wn X| j rö y* | j |	 Œ  }
 t |
 ƒ | j	 |
 ƒ Wn t
 k
 rò t |
 d ƒ n Xn5 | j |	 Œ  } | t k	 r+| j	 | ƒ | r(Pn  n  q+ WWn t k
 rOt j ƒ  } n XWd | r|t | rm| d n t | ƒ } n t | | ƒ } xF t | ƒ D]8 }
 y |
 j | ƒ t |
 d ƒ Wn t
 k
 rÏn Xq˜W| j ƒ  SX(   s’   Execute a call into multiple python functions/methods and return the
    result(s).

    ``caller_kwargs`` comes from _HookCaller.__call__().
    s"   hook call must provide argument %rs   did not yieldNi    s   has second yield(   R   R   t   reversedR6   R7   R	   R8   R9   R)   R;   R*   R   R   R   R   R   R+   R&   (   R0   R1   R2   R   R4   R   t	   teardownsR<   R=   R>   t   genR?   t   outcome(    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt
   _multicall   sL    $	
"(   i   i    (   R   R   R   t   version_infoR"   R   t	   ExceptionR	   t   objectR   R-   R.   RD   RE   RJ   (    (    (    s-   lib/python2.7/site-packages/pluggy/callers.pyt   <module>   s   	5	0