
^Yc           @` s  d  d l  m Z m Z m Z d  d l Z d  d l m Z m Z d  d l Z d  d l	 m
 Z
 d  d l m Z m Z m Z m Z d  d l Z e Z e j j d d  Z e r d  d l m Z n d	 d l m Z d
 e f d     YZ d e f d     YZ d e f d     YZ d e f d     YZ e d d d  Z  d e f d     YZ! d e f d     YZ" d e f d     YZ# d e# f d     YZ$ d e$ f d     YZ% d e$ f d      YZ& d! e# f d"     YZ' d# e' f d$     YZ( d% e# f d&     YZ) d' e# f d(     YZ* d) e# f d*     YZ+ d+ e# f d,     YZ, d- e# f d.     YZ- e. d/  Z/ e rrd0   Z0 n	 d1   Z0 d S(2   i    (   t   absolute_importt   divisiont   print_functionN(   t
   CO_VARARGSt   CO_VARKEYWORDS(   t   ref(   t   _PY2t   _PY3t   PY35t   safe_strt   reprt   reprlib(   t   format_exception_onlyi   t   Codec           B` sb   e  Z d  Z d   Z d   Z d Z d   Z e d    Z	 e d    Z
 d   Z e d  Z RS(	   s$    wrapper around Python code objects c         C` s~   t  | d  s t |  } n  y, | j |  _ | j d |  _ | j |  _ Wn$ t k
 rp t	 d | f   n X| |  _
 d  S(   Nt   co_filenamei   s   not a code object: %r(   t   hasattrt
   getrawcodeR   t   filenamet   co_firstlinenot   firstlinenot   co_namet   namet   AttributeErrort	   TypeErrort   raw(   t   selft   rawcode(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   __init__   s    c         C` s   |  j  | j  k S(   N(   R   (   R   t   other(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   __eq__    s    c         C` s   |  | k S(   N(    (   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   __ne__%   s    c         C` s[   y7 t  j j |  j j  } | j   s6 t d   n  Wn t k
 rV |  j j } n X| S(   ss    return a path object pointing to source code (note that it
        might not point to an actually existing file). s   py.path check failed.(   t   pyt   patht   localR   R   t   checkt   OSError(   R   t   p(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    (   s    c         C` s,   d d l  m } | j |  j  \ } } | S(   sS    return a _pytest._code.Source object for the full source file of the code
        i    (   t   source(   t   _pytest._codeR%   t
   findsourceR   (   R   R%   t   fullt   _(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt
   fullsource8   s    c         C` s   d d l  } | j j |  j  S(   sP    return a _pytest._code.Source object for the code object's source only
        i    N(   R&   t   _codet   SourceR   (   R   t   _pytest(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR%   @   s    c         C` sH   |  j  } | j } | r= | | j t @7} | | j t @7} n  | j |  S(   s    return a tuple with the argument names for the code object

            if 'var' is set True also return the names of the variable and
            keyword arguments when present
        (   R   t   co_argcountt   co_flagsR   R   t   co_varnames(   R   t   varR   t   argcount(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   getargsG   s    		N(   t   __name__t
   __module__t   __doc__R   R   t   Nonet   __hash__R   t   propertyR    R*   R%   t   FalseR3   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR      s   				t   Framec           B` sV   e  Z d  Z d   Z e d    Z d   Z d   Z d   Z d   Z	 e
 d  Z RS(   sg   Wrapper around a Python frame holding f_locals and f_globals
    in which expressions can be evaluated.c         C` sG   | j  d |  _ | j |  _ | j |  _ | |  _ t | j  |  _ d  S(   Ni   (   t   f_linenot   linenot	   f_globalst   f_localsR   R   t   f_codet   code(   R   t   frame(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   Y   s
    	c         C` sD   d d l  } |  j j d k r. | j j d  S|  j j j |  j  S(   s    statement this frame is at i    Nt    (   R&   RA   R*   R7   R+   R,   t   getstatementR=   (   R   R-   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt	   statement`   s    c         K` s/   |  j  j   } | j |  t | |  j |  S(   s    evaluate 'code' in the frame

            'vars' are optional additional local variables

            returns the result of the evaluation
        (   R?   t   copyt   updatet   evalR>   (   R   RA   t   varsR?   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRH   h   s    c         K` s9   |  j  j   } | j |  t j j | |  j |  d S(   s^    exec 'code' in the frame

            'vars' are optiona; additional local variables
        N(   R?   RF   RG   R   t   builtint   exec_R>   (   R   RA   RI   R?   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRK   s   s    c         C` s   t  j j |  S(   sL    return a 'safe' (non-recursive, one-line) string repr for 'object'
        (   R   t   iot   saferepr(   R   t   object(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR
   |   s    c         C` s   | S(   N(    (   R   RN   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   is_true   s    c         C` sY   g  } xL |  j  j |  D]8 } y | j | |  j | f  Wq t k
 rP q Xq W| S(   s    return a list of tuples (name, value) for all arguments

            if 'var' is set True also include the variable and keyword
            arguments when present
        (   RA   R3   t   appendR?   t   KeyError(   R   R1   t   retvalt   arg(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR3      s    (   R4   R5   R6   R   R9   RE   RH   RK   R
   RO   R:   R3   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR;   U   s   						t   TracebackEntryc           B` s   e  Z d  Z d Z d Z d d  Z d   Z e d    Z	 e d    Z
 d   Z e d    Z e d    Z d   Z e e d d d	  Z d
   Z d d  Z e e  Z d   Z d   Z d   Z e e d d d  Z RS(   s    a single entry in a traceback c         C` s&   | |  _  | |  _ | j d |  _ d  S(   Ni   (   t   _excinfot	   _rawentryt	   tb_linenoR=   (   R   t   rawentryt   excinfo(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR      s    		c         C` s   | d k s t   | |  _ d  S(   Nt   shortt   long(   s   shorts   long(   t   AssertionErrort   _repr_style(   R   t   mode(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   set_repr_style   s    c         C` s"   d d  l  } | j j |  j j  S(   Ni    (   R&   R+   R;   RV   t   tb_frame(   R   R-   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRB      s    c         C` s   |  j  |  j j j S(   N(   R=   RB   RA   R   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   relline   s    c         C` s   d |  j  j j |  j d f S(   Ns   <TracebackEntry %s:%d>i   (   RB   RA   R    R=   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   __repr__   s    c         C` s   |  j  j j } | j |  j  S(   s7    _pytest._code.Source object for the current statement (   RB   RA   R*   RD   R=   (   R   R%   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRE      s    c         C` s   |  j  j j S(   s    path to the source code (   RB   RA   R    (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR       s    c         C` s
   |  j  j S(   N(   RB   R?   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt	   getlocals   s    s   locals of underlaying framec         C` s   t  |  j j j d  S(   Ni    (   t   maxRB   RA   R   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   getfirstlinesource   s    c   	      C` s   d d l  m } |  j j j } | d k r/ d Sd } } | d k	 rx |  j j j } | d k	 rx | j | d  } qx n  |  j   } y% | |  j	 | d | \ } } } Wn t
 k
 r |  j	 d } n X| d k	 r | | | <n  | | | !S(   s    return failing source code. i    (   t   getstatementrange_astt   astnodei   N(   t   _pytest._code.sourceRf   RB   RA   R*   R7   R    t   getRe   R=   t   SyntaxError(	   R   t   astcacheRf   R%   t   keyRg   t   startR)   t   end(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt	   getsource   s$    
c         C` s   y |  j  j d } Wn: t k
 rP y |  j  j d } WqQ t k
 rL t SXn Xt j j |  r | |  j d k r{ d n	 |  j    S| Sd S(   s#   return True if the current frame has a var __tracebackhide__
            resolving to True

            If __tracebackhide__ is a callable, it gets called with the
            ExceptionInfo instance and can decide whether to hide the traceback.

            mostly for internal use
        t   __tracebackhide__N(
   RB   R?   RQ   R>   R:   R   RJ   t   callableRU   R7   (   R   t   tbh(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   ishidden   s    		%c         C` s   y t  |  j  } Wn t j j k
 r2 d } n X|  j j j } y t  |  j  j	   } Wn  t
 k
 rq   n d } n Xd | |  j d | | f S(   Ns   ???s     File %r:%d in %s
  %s
i   (   t   strR    R   t   errort   ErrorRB   RA   R   RE   t   lstript   KeyboardInterruptR=   (   R   t   fnR   t   line(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   __str__   s    

c         C` s   |  j  j j j S(   N(   RB   RA   R   R   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR      s    s   co_name of underlaying codeN(   R4   R5   R6   R7   R]   t   exprinfoR   R_   R9   RB   Ra   Rb   RE   R    Rc   t   localsRe   Ro   R%   Rs   R{   R   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRT      s&   							t	   Tracebackc           B` s_   e  Z d  Z e Z d d  Z d d d d d  Z d   Z d   d  Z	 d   Z
 d   Z RS(	   s_    Traceback objects encapsulate and offer higher level
        access to Traceback entries.
    c         ` sW      _  t | d  rC    f d   } t j  | |   n t j  |  d S(   sA    initialize from given python traceback object and ExceptionInfo t   tb_nextc         3` s4   x- |  d  k	 r/  j |  d   V|  j }  q Wd  S(   NRY   (   R7   t   EntryR   (   t   cur(   RY   R   (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   f  s    N(   RU   R   t   listR   (   R   t   tbRY   R   (    (   RY   R   s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s
    	c         C` s   x |  D] } | j  j } | j } | d k s: | | k r | d k sf t | d  sf | j |  r | d k s | j | k r | d k s | j  j j | k r t | j	 |  j
  Sq W|  S(   s   return a Traceback instance wrapping part of this Traceback

            by provding any combination of path, lineno and firstlineno, the
            first frame to start the to-be-returned traceback is determined

            this allows cutting the first part of a Traceback instance e.g.
            for formatting reasons (removing some uninteresting bits that deal
            with handling of the exception/traceback)
        t   reltoN(   RB   RA   R    R7   R   R   R=   R   R~   RV   RU   (   R   R    R=   R   t   excludepatht   xRA   t   codepath(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   cut  s    
	!c         C` sI   t  t |   j |  } t | t t d    rE |  j |  } n  | S(   Ni    (   t   superR~   t   __getitem__t
   isinstancet   typet   slicet	   __class__(   R   Rl   t   val(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   (  s    c         C` s   |  j    S(   N(   Rs   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   <lambda>.  s    c         C` s   t  t | |   |  j  S(   sv   return a Traceback instance with certain items removed

            fn is a function that gets a single argument, a TracebackEntry
            instance, and should return True when the item should be added
            to the Traceback, False when not

            by default this removes all the TracebackEntries which are hidden
            (see ishidden() above)
        (   R~   t   filterRU   (   R   Ry   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   .  s    
c         C` sJ   x? t  d t |   d d  D]  } |  | } | j   s | Sq W|  d S(   sc    return last non-hidden traceback entry that lead
        to the exception of a traceback.
        ii   (   t   ranget   lenRs   (   R   t   it   entry(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   getcrashentry:  s
    $
c   	   	   C` s   i  } x t  |   D] \ } } | j j j t | j j j  | j f } | j | g   } | r | j } | j } x9 | D]. } | j	 | j
 t d | d |  rz | Sqz Wn  | j | j j  q Wd S(   s    return the index of the frame/TracebackEntry where recursion
            originates if appropriate, None if no recursion occurred
        t   __recursioncache_locals_1t   __recursioncache_locals_2N(   t	   enumerateRB   RA   R    t   idR   R=   t
   setdefaultR?   RO   RH   t   co_equalRP   R7   (	   R   t   cacheR   R   Rl   t   lR   t   loct   otherloc(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   recursionindexD  s    *		N(   R4   R5   R6   RT   R   R7   R   R   R   R   R   R   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR~     s   		
s6   __recursioncache_locals_1 == __recursioncache_locals_2t   ?RH   t   ExceptionInfoc           B` s   e  Z d  Z d Z e r d n d Z d d d  Z d   Z e	 d  Z
 d   Z d   Z e	 d	 e	 e e	 d
  Z d   Z d   Z d   Z RS(   sX    wraps sys.exc_info() objects and offers
        help for navigating the traceback.
    RC   s   AssertionError(u'assert s   AssertionError('assert c         C` s  d d  l  } | d  k r t j   } | d  k r t | d t  r t | d d d   } | d  k r~ t j j	 | d  } n  | r | j
 |  j  r d |  _ q q n  | |  _ | d |  _ | d |  _ | d |  _ |  j j |  _ | j j |  j d t |   |  _ d  S(   Ni    i   t   msgs   AssertionError: i   RY   (   R&   R7   t   syst   exc_infoR   R\   t   getattrR   RL   RM   t
   startswitht   _assert_start_reprt
   _striptextRU   R   t   valueR   R4   t   typenameR+   R~   R   t	   traceback(   R   t   tupR|   R-   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   g  s    	c         C` s   d |  j  t |  j  f S(   Ns   <ExceptionInfo %s tblen=%d>(   R   R   R   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRb   }  s    c         C` se   t  |  j |  j  } d j |  } | j   } | ra | j |  j  ra | t |  j  } qa n  | S(   s4   return the exception as a string

            when 'tryshort' resolves to True, and the exception is a
            _pytest._code._AssertionError, only the actual exception part of
            the exception representation is returned (so 'AssertionError: ' is
            removed from the beginning)
        RC   (   R   R   R   t   joint   rstripR   R   R   (   R   t   tryshortt   linest   text(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   exconly  s    c         C` s   t  |  j |  S(   s4    return True if the exception is an instance of exc (   R   R   (   R   t   exc(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   errisinstance  s    c         C` sQ   |  j  d t  } |  j j   } | j j j j | j } } t	 | | d |  S(   NR   i   (
   R   t   TrueR   R   RB   RA   R   R   R=   t   ReprFileLocation(   R   R   R   R    R=   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   _getreprcrash  s    R[   c         C` s~   | d k rJ t  t t j j j |  j |  j |  j d j   |  j	    St
 d | d | d | d | d |  } | j |   S(   sA   return str()able representation of this exception info.
            showlocals: show locals per traceback entry
            style: long|short|no|native traceback style
            tbfilter: hide entries (where __tracebackhide__ is true)

            in case of style==native, tbfilter and showlocals is ignored.
        t   nativei    t
   showlocalst   stylet   abspatht   tbfiltert   funcargs(   t   ReprExceptionInfot   ReprTracebackNativeR   t   stdR   t   format_exceptionR   R   RV   R   t   FormattedExcinfot   repr_excinfo(   R   R   R   R   R   R   t   fmt(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   getrepr  s    	c         C` s9   |  j  d } t | j | j d |  j    } t |  S(   Nii   (   R   R   R    R=   R   Rt   (   R   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR{     s    "c         C` s9   |  j  d } t | j | j d |  j    } t |  S(   Nii   (   R   R   R    R=   R   t   unicode(   R   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   __unicode__  s    "c         C` sI   t  } t j | t |  j   sE d sE t d j | |  j    n  t  S(   s  
        Match the regular expression 'regexp' on the string representation of
        the exception. If it matches then True is returned (so that it is
        possible to write 'assert excinfo.match()'). If it doesn't match an
        AssertionError is raised.
        i    s$   Pattern '{0!s}' not found in '{1!s}'(   R   t   ret   searchRt   R   R\   t   format(   R   t   regexpRp   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   match  s
    N(   R4   R5   R6   R   R   R   R7   R   Rb   R:   R   R   R   R   R   R{   R   R   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   `  s   					R   c           B` s   e  Z d  Z d Z d Z e d e e e d  Z d   Z d   Z	 d   Z
 d   Z d	 d e d
  Z d e d  Z d   Z d d  Z d   Z d   Z d   Z d   Z RS(   s@    presenting information about failing Functions and Generators. t   >t   ER[   c         C` s:   | |  _  | |  _ | |  _ | |  _ | |  _ i  |  _ d  S(   N(   R   R   R   R   R   Rk   (   R   R   R   R   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    					c         C` s   y# t  | j t |  d   } WnL t k
 r9   n9 y t  | d  } Wqr t k
 rf   qr d SXn Xd t |  t | j    S(   Ni   ii    i   (   Rt   RD   R   Rx   Rw   (   R   R%   t   s(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt
   _getindent  s    #	c         C` s1   | j  |  j  } | d  k	 r- | j   } n  | S(   N(   Ro   Rk   R7   t   deindent(   R   R   R%   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   _getentrysource  s    c         C` s   t  j j |  S(   N(   R   RL   RM   (   R   t   obj(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt	   _saferepr  s    c         C` s_   |  j  r[ g  } x? | j j d t  D]( \ } } | j | |  j |  f  q% Wt |  Sd  S(   NR1   (   R   RB   R3   R   RP   R   t   ReprFuncArgs(   R   R   t   argst   argnamet   argvalue(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt	   repr_args  s
    	" ic   
      C` s_  d d l  } g  } | d k s3 | t | j  k rN | j j d  } d } n  | d k  rm | t |  7} n  d } | r | j | | j | j    nu x& | j |  D] } | j | |  q W| j |  j d | j |  x* | j | d D] } | j | |  q W| d k	 r[| r'd n |  j	 |  }	 | j
 |  j | d |	 d	 t  n  | S(
   s.    return formatted and marked up source lines. i    Ns   ???s       s      i   i   t   indentt   markall(   R&   R7   R   R   R+   R,   RP   t   stript   flow_markerR   t   extendt   get_exconlyR   (
   R   R%   t
   line_indexRY   RZ   R-   R   t   space_prefixRz   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt
   get_source  s&    !	!%i   c         C` sq   g  } d | } | j  d t  j d  } |  j | d } x. | D]& } | j | |  | sC | } qC qC W| S(   Nt    R   s   
i   (   R   R   t   splitt   fail_markerRP   (   R   RY   R   R   R   t   exlinest
   failindentRz   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    
c         C` s   |  j  r g  } g  | D] } | d d k r | ^ q } | j   xZ | D]R } | | } | d k ru | j d  qI |  j |  } | j d | | f  qI Wt |  Sd  S(   Ni    t   @t   __builtins__s   __builtins__ = <builtins>s
   %-10s = %s(   R   t   sortRP   R   t
   ReprLocals(   R   R}   R   R   t   keysR   R   t   str_repr(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   repr_locals  s    	)

c         C` s  d d  l  } |  j |  } | d  k rB | j j d  } d } n | j t | j   d  } g  } | j } | d  k r |  j	 } n  | d
 k rm| d k } | s |  j
 |  n d  }	 |  j | | | d | }
 | j |
  | r d | j } n | r| j pd } |  j | j  } t | | j d |  } d  } | sW|  j | j  } n  t | |	 | | |  S| r| j |  j | d d	  n  t | d  d  d  |  S(   Ni    s   ???RZ   R[   s   in %sRC   i   R   i   (   s   shorts   long(   R&   R   R7   R+   R,   R=   Rd   Re   R]   R   R   R   R   R   R   t	   _makepathR    R   R   R}   t	   ReprEntryR   (   R   R   RY   R-   R%   R   R   R   RZ   t   reprargsR   t   messageR    t   filelocreprt
   localsrepr(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   repr_traceback_entry.  s6    		c         C` sh   |  j  sd y t j j   j |  } Wn t k
 r9 | SXt |  t t |   k  rd | } qd n  | S(   N(   R   R   R    R!   t   bestrelpathR#   R   Rt   (   R   R    t   np(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   O  s    	c   
      C` s   | j  } |  j r! | j   } n  t |  rE |  j |  \ } } n d  } | d } g  } xQ t |  D]C \ } } | | k r | p d  } |  j | |  }	 | j |	  qh Wt	 | | d |  j
 S(   NiR   (   R   R   R   t   is_recursion_errort   _truncate_recursive_tracebackR7   R   R   RP   t   ReprTracebackR   (
   R   RY   R   t	   extralinet   lastt   entriest   indexR   t   einfot	   reprentry(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   repr_tracebackY  s    		
c      
   C` s   y | j    } Wne t k
 rw } d } d j d t |  j d t |  d | d t |   } | |  | | } n* X| d	 k	 r d } | | d  } n d	 } | | f S(
   sC  
        Truncate the given recursive traceback trying to find the starting point
        of the recursion.

        The detection is done by going through each traceback entry and finding the
        point in which the locals of the frame are equal to the locals of a previous frame (see ``recursionindex()``.

        Handle the situation where the recursion process might raise an exception (for example
        comparing numpy arrays using equality raises a TypeError), in which case we do our best to
        warn the user of the error and show a limited traceback.
        i
   s  !!! Recursion error detected, but an error occurred locating the origin of recursion.
  The following exception happened when comparing locals in the stack frame:
    {exc_type}: {exc_msg}
  Displaying first and last {max_frames} stack frames out of {total}.t   exc_typet   exc_msgt
   max_framest   totals/   !!! Recursion detected (same locals & position)i   N(   R   t	   ExceptionR   R   R4   R	   R   R7   (   R   R   R   t   eR  R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   k  s    	0c         C` sw  t  r. |  j |  } | j   } t | |  Sg  } | j } d  } x| d  k	 r^| rv |  j |  } | j   } n- t t j j	 j
 t |  | d    } d  } | | | | f g 7} | j d  k	 r| j } | j r t t |  | | j f  n d  } d } qF | j d  k	 rU| j } | j rFt t |  | | j f  n d  } d } qF d  } qF W| j   t |  Sd  S(   NsD   The above exception was the direct cause of the following exception:sC   During handling of the above exception, another exception occurred:(   R   R  R   R   R   R7   R   R   R   R   R   R   t	   __cause__t   __traceback__R   t   __context__t   reverset   ExceptionChainRepr(   R   RY   t   reprtracebackt	   reprcrasht
   repr_chainR
  t   descr(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s2    	'	-		-	

N(   R4   R5   R6   R   R   R:   R   R   R   R   R   R   R7   R   R   R   R   R   R  R   R   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    					!	
		 t   TerminalReprc           B` s#   e  Z d    Z d   Z d   Z RS(   c         C` s(   |  j    } t r$ | j d  } n  | S(   Ns   utf-8(   R   R   t   encode(   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR{     s    c         C` sA   t  j j   } t  j j d |  } |  j |  | j   j   S(   Nt   file(   R   RL   t   TextIOt   TerminalWritert
   toterminalt   getvalueR   (   R   RL   t   tw(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    c         C` s   d |  j  t |   f S(   Ns   <%s instance at %0x>(   R   R   (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyRb     s    (   R4   R5   R{   R   Rb   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s   		t   ExceptionReprc           B` s&   e  Z d    Z d d  Z d   Z RS(   c         C` s   g  |  _  d  S(   N(   t   sections(   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    t   -c         C` s   |  j  j | | | f  d  S(   N(   R  RP   (   R   R   t   contentt   sep(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt
   addsection  s    c         C` s>   x7 |  j  D], \ } } } | j | |  | j |  q
 Wd  S(   N(   R  R   Rz   (   R   R  R   R  R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s    (   R4   R5   R   R!  R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s   	R  c           B` s   e  Z d    Z d   Z RS(   c         C` sB   t  t |   j   | |  _ | d d |  _ | d d |  _ d  S(   Nii    i   (   R   R  R   t   chainR  R  (   R   R"  (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    	c         C` sv   xY |  j  D]N } | d j |  | d d  k	 r
 | j d  | j | d d t q
 q
 Wt t |   j |  d  S(   Ni    i   RC   t   yellow(   R"  R  R7   Rz   R   R   R  (   R   R  t   element(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s    (   R4   R5   R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s   	R   c           B` s   e  Z d    Z d   Z RS(   c         C` s)   t  t |   j   | |  _ | |  _ d  S(   N(   R   R   R   R  R  (   R   R  R  (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    	c         C` s*   |  j  j |  t t |   j |  d  S(   N(   R  R  R   R   (   R   R  (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s    (   R4   R5   R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s   	R   c           B` s    e  Z d  Z d   Z d   Z RS(   s   _ c         C` s   | |  _  | |  _ | |  _ d  S(   N(   t   reprentriesR   R   (   R   R%  R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    		c         C` s   x t  |  j  D] \ } } | j d k r; | j d  n  | j |  | t |  j  d k  r |  j | d } | j d k s | j d k r | j d k r | j |  j  q q q W|  j r | j |  j  n  d  S(   NR[   RC   i   RZ   (	   R   R%  R   Rz   R  R   R   t   entrysepR   (   R   R  R   R   t
   next_entry(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s    	(   R4   R5   R&  R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s   	R   c           B` s   e  Z d    Z RS(   c         C` s(   d |  _  t |  g |  _ d  |  _ d  S(   NR   (   R   t   ReprEntryNativeR%  R7   R   (   R   t   tblines(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s    	(   R4   R5   R   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s   R(  c           B` s    e  Z d  Z d   Z d   Z RS(   R   c         C` s   | |  _  d  S(   N(   R   (   R   R)  (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   
  s    c         C` s   | j  d j |  j   d  S(   NRC   (   t   writeR   R   (   R   R  (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s    (   R4   R5   R   R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR(    s   	R   c           B` s)   e  Z d  Z d   Z d   Z d   Z RS(   s   _ c         C` s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   t   reprfuncargst
   reprlocalst   reprfilelocR   (   R   R   R+  R,  R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s
    				c         C` s  |  j  d k r_ |  j j |  x9 |  j D]. } | j d  } | j | d t d | q) Wd  S|  j r{ |  j j |  n  x9 |  j D]. } | j d  } | j | d t d | q W|  j r | j d  |  j j |  n  |  j r|  j r| j d  n  |  j j |  n  d  S(   NRZ   s   E   t   boldt   redRC   (	   R   R-  R  R   R   Rz   R   R+  R,  (   R   R  Rz   R/  (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR    s$    				c         C` s#   d d j  |  j  |  j |  j f S(   Ns   %s
%s
%ss   
(   R   R   R,  R-  (   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR{   0  s    (   R4   R5   t	   localssepR   R  R{   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR     s   		R   c           B` s   e  Z d    Z d   Z RS(   c         C` s%   t  |  |  _ | |  _ | |  _ d  S(   N(   Rt   R    R=   R   (   R   R    R=   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   6  s    	c         C` sk   |  j  } | j d  } | d k r1 | |  } n  | j |  j d t d t | j d |  j | f  d  S(   Ns   
iR.  R/  s   :%s: %s(   R   t   findR*  R    R   Rz   R=   (   R   R  R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR  ;  s    	(   R4   R5   R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   5  s   	R   c           B` s   e  Z d    Z d   Z RS(   c         C` s   | |  _  d  S(   N(   R   (   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   F  s    c         C` s%   x |  j  D] } | j |  q
 Wd  S(   N(   R   Rz   (   R   R  Rz   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR  I  s    (   R4   R5   R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   E  s   	R   c           B` s   e  Z d    Z d   Z RS(   c         C` s   | |  _  d  S(   N(   R   (   R   R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   N  s    c         C` s   |  j  r d } x |  j  D]{ \ } } d | | f } t |  t |  d | j k rw | rn | j |  n  | } q | r | d | 7} q | } q W| r | j |  n  | j d  n  d  S(   NRC   s   %s = %si   s   , (   R   R   t	   fullwidthRz   (   R   R  t	   linesofarR   R   t   ns(    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR  Q  s    	#	
(   R4   R5   R   R  (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   M  s   	c         C` s   y |  j  SWn t k
 r t |  d |   }  t |  d |   }  t |  d |   }  t |  d |   }  | r t |  d  r t |  d  r t j j j |   r t |  j	 d t
 } t | d  r | Sq n  |  SXd S(	   s(    return code object for given function. t   im_funct	   func_codeR@   t   __code__R   t   __call__t   trycallN(   R7  R   R   R   R   R   t   inspectt   isclassR   R8  R:   (   R   R9  R   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   d  s    %
c         C` s   |  j  t  S(   N(   R   t   RecursionError(   RY   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   v  s    c         C` sC   |  j  t  s t Sy d t |  j  k SWn t k
 r> t SXd  S(   Ns    maximum recursion depth exceeded(   R   t   RuntimeErrorR:   Rt   R   t   UnicodeError(   RY   (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyR   y  s    (1   t
   __future__R    R   R   R   R:  R   R   R   t   weakrefR   t   _pytest.compatR   R   R   R	   R   R
   t   builtin_reprRJ   t
   _tryimportR   R   R   t   _py2tracebackRN   R   R;   RT   R   R~   t   compileR   R   R   R  R  R  R   R   R   R(  R   R   R   R   R   R   R   (    (    (    s2   /tmp/pip-build-hU8Cw8/pytest/_pytest/_code/code.pyt   <module>   sD   "B=p[g
	%