ó
çiõ\c           @` s'  d  d l  m Z d  d l  m Z d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l m Z d  d l m Z d  d l Z d  d l Z d e f d „  ƒ  YZ d d	 d  d  d
 „ Z d „  Z d „  Z d „  Z d „  Z d „  Z e d d „ Z d S(   i    (   t   absolute_import(   t   division(   t   print_functionN(   t   PyCF_ONLY_AST(   t   bisect_rightt   Sourcec           B` s­   e  Z d  Z d Z d „  Z d „  Z d Z d „  Z d „  Z	 d „  Z
 d d d d
 „ Z d d „ Z d „  Z d „  Z d „  Z e d „ Z d „  Z d d d d d d „ Z RS(   sZ    an immutable object holding a source code fragment,
        possibly deindenting it.
    i    c         O` só   g  |  _  } | j d t ƒ } xÍ | D]Å } | s; g  } nŽ t | t ƒ rV | j  } ns t | t t f ƒ r g  | D] } | j d ƒ ^ qr } n9 t | t j	 ƒ r´ | j
 d ƒ } n t | d | ƒj  } | rÞ t | ƒ } n  | j | ƒ q& Wd  S(   Nt   deindents   
(   t   linest   gett   Truet
   isinstanceR   t   tuplet   listt   rstript   sixt   string_typest   splitt	   getsourceR   t   extend(   t   selft   partst   kwargsR   t   det   partt	   partlinest   x(    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   __init__   s    	%c         C` sL   y |  j  | j  k SWn1 t k
 rG t | t ƒ rC t |  ƒ | k St SXd  S(   N(   R   t   AttributeErrorR
   t   strt   False(   R   t   other(    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   __eq__-   s    c         C` sb   t  | t ƒ r |  j | S| j d k r8 t d ƒ ‚ n  t ƒ  } |  j | j | j !| _ | Sd  S(   Ni   s!   cannot slice a Source with a step(   Ni   (	   R
   t   intR   t   stept   Nonet
   IndexErrorR   t   startt   stop(   R   t   keyt	   newsource(    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   __getitem__7   s    	c         C` s   t  |  j ƒ S(   N(   t   lenR   (   R   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   __len__A   s    c         C` sš   d t  |  ƒ } } x. | | k  rC |  j | j ƒ  rC | d 7} q Wx2 | | k rx |  j | d j ƒ  rx | d 8} qG Wt ƒ  } |  j | | !| j (| S(   s]    return new source object with trailing
            and leading blank lines removed.
        i    i   (   R)   R   t   stripR   (   R   R$   t   endt   source(    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR+   D   s    #'	t    t    i   c         C` s\   t  | ƒ } t  | ƒ } t  ƒ  } g  |  j D] } | | ^ q+ } | j | | j | _ | S(   se    return a copy of the source object with
            'before' and 'after' wrapped around it.
        (   R   R   (   R   t   beforet   aftert   indentR'   t   lineR   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt	   putaroundQ   s    	 c         C` s0   t  ƒ  } g  |  j D] } | | ^ q | _ | S(   sl    return a copy of the source object with
            all lines indented by the given indent-string.
        (   R   R   (   R   R2   R'   R3   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR2   \   s    	#c         C` s    |  j  | ƒ \ } } |  | | !S(   sc    return Source statement which contains the
            given linenumber (counted from 0).
        (   t   getstatementrange(   R   t   linenoR$   R,   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   getstatementd   s    c         C` sS   d | k o t  |  ƒ k  n s1 t d ƒ ‚ n  t | |  ƒ \ } } } | | f S(   s{    return (start, end) tuple which spans the minimal
            statement region which containing the given lineno.
        i    s   lineno out of range(   R)   R#   t   getstatementrange_ast(   R   R6   t   astR$   R,   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR5   k   s    "c         C` s    t  ƒ  } t |  j ƒ | j (| S(   s&   return a new source object deindented.(   R   R   R   (   R   R'   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR   t   s    	c         C` sy   d d l  m } | r+ t |  j ƒ  ƒ } n t |  ƒ } y | | d ƒ Wn% t k
 r_ ‚  n t k
 rp t SXt Sd S(   sb    return True if source is parseable, heuristically
            deindenting it by default.
        i    (   t   suites   
N(   t   parserR:   R   R   t   KeyboardInterruptt	   ExceptionR   R	   (   R   R   t   syntax_checkerR-   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   isparseablez   s    c         C` s   d j  |  j ƒ S(   Ns   
(   t   joinR   (   R   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   __str__Ž   s    t   execc         C` sÕ  | s% t  j j | ƒ j d d ƒ r¯ | d k rC t j d ƒ } n  | j j | j	 } } d |  j
 } |  j j
 d 7_
 | s• | d | | f } q¯ | d | | | f } n  d j |  j ƒ d }	 y t |	 | | | ƒ }
 Wn¥ t k
 r…t j ƒ  d } |  j | j  } | j r2| j d | j d	 ƒ n  | j d
 | ƒ t d j | ƒ ƒ } | j | _ | j | _ | j | _ | ‚ nL X| t @r”|
 Sg  |  j D] } | d ^ qž} d d | | f t j | <|
 Sd S(   s­    return compiled code object. if filename is None
            invent an artificial filename which displays
            the source/line position of the caller frame.
        t   filei    i   s   <%d-codegen s   %s:%d>s	   %r %s:%d>s   
R/   t   ^s*   (code was compiled probably from here: %s)N(   t   pyt   patht   localt   checkR"   t   syst	   _getframet   f_codet   co_filenamet   f_linenot   _compilecountert	   __class__R@   R   t   compilet   SyntaxErrort   exc_infoR6   t   offsett   appendt   textt	   _AST_FLAGt	   linecachet   cache(   R   t   filenamet   modet   flagt   dont_inheritt	   _genframet   fnR6   t   baseR-   t   cot   ext   msglinest   newexR   R   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyRP   ‘   s8    %	

 Ns       s       (   t   __name__t
   __module__t   __doc__RN   R   R   R"   t   __hash__R(   R*   R+   R4   R2   R7   R5   R   R	   R?   RA   RP   (    (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR      s    			
							RB   c         C` sb   t  |  t j ƒ r( t |  | | | | ƒ St j d ƒ } t |  ƒ } | j | | | d | ƒ} | S(   sÙ    compile the given source to a raw code object,
        and maintain an internal cache which allows later
        retrieval of the source code for the code object
        and any recursively created code objects.
    i   R]   (   R
   R9   t   ASTRP   RI   RJ   R   (   R-   RY   RZ   t   flagsR\   R]   t   sR`   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   compile_¾   s    c         C` só   d d l  m } y | |  ƒ } WnŸ t k
 rÁ y" t j |  ƒ pN t j |  ƒ } Wn t k
 rf d SX| r t j j | ƒ p‚ d } d } | rÔ y t
 |  ƒ \ } } Wq¾ t k
 rº q¾ XqÔ n X| j } | j } t | t ƒ sé t ‚ | | f S(   sš    Return source location (path, lineno) for the given object.
    If the source cannot be determined return ("", -1).

    The line number is 0-based.
    i   (   t   CodeR.   iÿÿÿÿ(   R.   iÿÿÿÿN(   t   codeRl   t	   TypeErrort   inspectt   getsourcefilet   getfileRE   RF   RG   R"   t
   findsourcet   IOErrort   firstlinenoR
   R    t   AssertionError(   t   objRl   Rm   R^   t   fspathR6   t   _(    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   getfslinenoÍ   s&    "		c         C` sc   y t  j |  ƒ \ } } Wn t k
 r- d SXt ƒ  } g  | D] } | j ƒ  ^ q> | _ | | f S(   Niÿÿÿÿ(   Niÿÿÿÿ(   Ro   Rr   R=   R"   R   R   R   (   Rv   t   sourcelinesR6   R-   R3   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyRr   ð   s    	"c         K` sk   d d l  m } | |  ƒ }  y t j |  ƒ } Wn t k
 rH d } n Xt | t ƒ s^ t ‚ t | |  S(   Ni   (   t
   getrawcodes<   "Buggy python version consider upgrading, cannot get source"(	   Rm   R{   Ro   R   t   IndentationErrorR
   R   Ru   R   (   Rv   R   R{   t   strsrc(    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR   ú   s    
c         C` s   t  j d j |  ƒ ƒ j ƒ  S(   Ns   
(   t   textwrapt   dedentR@   t
   splitlines(   R   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyR     s    c   
      C` sü   d d  l  } g  } x‘ | j | ƒ D]€ } t | | j | j f ƒ r" | j | j d ƒ xH d D]= } t | | d  ƒ } | r^ | j | d j d d ƒ q^ q^ Wq" q" W| j	 ƒ  t
 | |  ƒ } | | d } | t | ƒ k rè d  }	 n
 | | }	 | |	 f S(   Ni    i   t	   finalbodyt   orelse(   R   R‚   (   R9   t   walkR
   t   stmtt   ExceptHandlerRT   R6   t   getattrR"   t   sortR   R)   (
   R6   t   nodeR9   t   valuesR   t   namet   valt   insert_indexR$   R,   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   get_statement_startend2
  s     *
	
c   
   	   ` s™  | d  k rP t | ƒ } t j ƒ  ' t j d ƒ t | d d t ƒ } Wd  QXn  t |  | ƒ \ } } | d  k rƒ t | j	 ƒ } n  | | d k rDt
 j ƒ  } | j	 | d j ƒ  | _ d „  | j	 | | !Dƒ ‰  y4 x- t j ‡  f d †  ƒ D] } | j | Œ  qï WWqDt
 j t f k
 r0| j | } qDt k
 r@qDXn  xE | r‹| j	 | d j ƒ  }	 |	 j d ƒ sz|	 r‡| d 8} qGPqGW| | | f S(	   Nt   ignoreR-   RB   i   i    c         s` s   |  ] } | d  Vq d S(   s   
N(    (   t   .0R   (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pys	   <genexpr>9  s    c           ` s
   t  ˆ  ƒ S(   N(   t   next(    (   t   it(    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   <lambda>;  R.   t   #(   R"   R   t   warningst   catch_warningst   simplefilterRP   RV   R   R)   R   Ro   t   BlockFindert   isspacet   startedt   tokenizet   generate_tokenst
   tokeneatert
   EndOfBlockR|   t   lastR=   t   lstript
   startswith(
   R6   R-   t	   assertiont   astnodet   contentR$   R,   t   block_findert   tokR3   (    (   R‘   s3   lib/python2.7/site-packages/_pytest/_code/source.pyR8   "  s2    	(   t
   __future__R    R   R   R9   Ro   RW   RI   R~   Rš   R”   R   RV   t   bisectR   RE   R   t   objectR   R"   Rk   Ry   Rr   R   R   R   R   R8   (    (    (    s3   lib/python2.7/site-packages/_pytest/_code/source.pyt   <module>   s*   ª	#	
			