
^Yc           @   s  d  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	 m Z m Z d d l m Z d d l m Z d d l m Z m Z m Z m Z m Z d d	 l m Z m Z m Z d d
 l m Z m Z m 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 j$ d d  f d     YZ% e d d    e& e' e j( j) d d    Z* d e f d     YZ+ d e f d      YZ, e* rd! g Z- d"   Z. d d#  Z/ n  d S($   s   Code parsing for coverage.py.iN(   t   env(   t   range(   t   bytes_to_intst   string_class(   t   CodeObjects(   t   short_stack(   t   contractt
   join_regext   new_contractt	   nice_pairt   one_of(   t   NoSourcet	   NotPythont   StopEverything(   t   compile_unicodet   generate_tokenst   neuter_encoding_declarationt   PythonParserc           B   s   e  Z d  Z e d d  d d d d   Z e d    Z d   Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d d  Z RS(   s   Parse code to find executable lines, excluded lines, etc.

    This information is all based on static analysis: no code execution is
    involved.

    t   texts   unicode|Nonec         C   s(  | s | s t  d   | p! d |  _ | |  _ |  j s d d l m } y | |  j  |  _ Wq t k
 r } t d |  j | f   q Xn  | |  _ |  j j d  |  _	 t
   |  _ t
   |  _ t
   |  _ t
   |  _ t
   |  _ t
   |  _ t |  _ i  |  _ d |  _ d |  _ d |  _ d S(   s   
        Source can be provided as `text`, the text itself, or `filename`, from
        which the text will be read.  Excluded lines are those that match
        `exclude`, a regex.

        s*   PythonParser needs either text or filenames   <code>i(   t   get_python_sources   No source for code: '%s': %ss   
N(   t   AssertionErrort   filenameR   t   coverage.pythonR   t   IOErrorR   t   excludet   splitt   linest   sett
   statementst   excludedt   raw_statementst   raw_excludedt   raw_classdefst   raw_docstringst   Falset   show_tokenst
   _multilinet   Nonet   _byte_parsert	   _all_arcst   _missing_arc_fragments(   t   selfR   R   R   R   t   err(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   __init__   s.    							c         C   s.   |  j  s' t |  j d |  j |  _  n  |  j  S(   s   Create a ByteParser on demand.R   (   R&   t
   ByteParserR   R   (   R)   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   byte_parser\   s    	c         G   s   t  |  } t j r' | j d  } n  t j |  } t   } xB t |  j d d D]+ \ } } | j	 |  rU | j
 |  qU qU W| S(   s   Find the lines matching one of a list of regexes.

        Returns a set of line numbers, the lines that contain a match for one
        of the regexes in `regexes`.  The entire line needn't match, just a
        part of it.

        t   utf8t   starti   (   R   R    t   PY2t   decodet   ret   compileR   t	   enumerateR   t   searcht   add(   R)   t   regexest   combinedt   regex_ct   matchest   it   ltext(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   lines_matchingc   s    		"c         C   s#  |  j  r! |  j |  j   |  _ n  d } d } t } t } t j } d } t } t } t |  j	  }	 x|	 D]\ }
 } \ } } \ } } } |  j
 r d t j j |
 |
  t | | f  | | f GHn  |
 t j k r | d 7} n|
 t j k r | d 8} n|
 t j k r0| d k r|  j j |  qnP|
 t j k r| d k r| |  j k p]| } | r| r|  j j |  | } t } t } qq| d k r| r| |  j k rt } n  | r|  j j |  qqn |
 t j k r| t j k r|  j j t | | d   nd |
 t j k r| d k	 rq| | k rqx+ t | | d  D] } | |  j | <qWWn  d } t } n  | j   r|
 t j k rt } | d k r| } | r| | k rt } n  | r|  j j |  n  t } qn  |
 } qj W| s|  j j |  j j    n  d S(   sw   Parse the source to find the interesting facts about its lines.

        A handful of attributes are updated.

        i    s   %10s %5s %-20r %ri   t   classt   :t   @N(   R   R=   R   R"   t   tokent   INDENTR%   t   TrueR   R   R#   t   tokenizet   tok_namet   getR	   t   DEDENTt   NAMER    R6   t   OPt   STRINGR!   t   updateR   t   NEWLINER$   t   stript   COMMENTR   R-   t   _find_statements(   R)   t   indentt   exclude_indentt	   excludingt   excluding_decoratorst   prev_toktypet
   first_linet   emptyt   first_on_linet   tokgent   toktypet   ttextt   slinenot   _t   elinenoR<   t   should_excludet   l(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt
   _raw_parseu   sp    		(		 		
c         C   s   |  j  j | |  S(   s?   Return the first line number of the statement including `line`.(   R$   RF   (   R)   t   line(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyRU      s    c            s   t    f d   | D  S(   s   Map the line numbers in `lines` to the correct first line of the
        statement.

        Returns a set of the first lines.

        c         3   s   |  ] }   j  |  Vq d  S(   N(   RU   (   t   .0R_   (   R)   (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pys	   <genexpr>   s    (   R   (   R)   R   (    (   R)   s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   first_lines   s    c         C   s   |  j  |  S(   s)   Implement `FileReporter.translate_lines`.(   Rc   (   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   translate_lines   s    c         C   s5   g  | D]* \ } } |  j  |  |  j  |  f ^ q S(   s(   Implement `FileReporter.translate_arcs`.(   RU   (   R)   t   arcst   at   b(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   translate_arcs   s    c         C   s   y |  j    Wnk t j t f k
 r{ } t | d  rD | j } n | j d d } t d |  j | j d | f   n X|  j	 |  j
  |  _ |  j |  j B} |  j | } |  j	 |  | |  _ d S(   s   Parse source text to find executable lines, excluded lines, etc.

        Sets the .excluded and .statements attributes, normalized to the first
        line of multi-line statements.

        t   linenoi   i    u5   Couldn't parse '%s' as Python source: '%s' at line %dN(   R`   RD   t
   TokenErrort   IndentationErrort   hasattrRi   t   argsR   R   Rc   R   R   R!   R   R   (   R)   R*   Ri   t   ignoret   starts(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   parse_source   s    !c         C   s#   |  j  d k r |  j   n  |  j  S(   s   Get information about the arcs available in the code.

        Returns a set of line number pairs.  Line numbers have been normalized
        to the first line of multi-line statements.

        N(   R'   R%   t   _analyze_ast(   R)   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyRe      s    c         C   s   t  |  j |  j |  j  } | j   t   |  _ xZ | j D]O \ } } |  j |  } |  j |  } | | k r; |  j j	 | | f  q; q; W| j
 |  _ d S(   sk   Run the AstArcAnalyzer and save its results.

        `_all_arcs` is the set of arcs in the code.

        N(   t   AstArcAnalyzerR   R   R$   t   analyzeR   R'   Re   RU   R6   t   missing_arc_fragmentsR(   (   R)   t   aaat   l1t   l2t   fl1t   fl2(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyRq   
  s    
c         C   s   t  j t  } xf |  j   D]X \ } } | d k  r: q n  | |  j k rO q n  | |  j k rd q n  | | c d 7<q Wx0 |  j D]% } | | k r | | c d 8<q q W| S(   sY   Get a count of exits from that each line.

        Excluded lines are excluded.

        i    i   (   t   collectionst   defaultdictt   intRe   R   R    (   R)   t   exit_countsRv   Rw   R_   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR}     s    c         C   s  |  j  d k r |  j   n  | } | rx | d k  rx | | k rx | | f | k rx | | f |  j  k rx | | } } n  |  j  j | | f d g  } g  } x | D] } | \ } }	 |	 d k r| d k  r | | f |  j  k r |  j | |  Sd }	 qd }	 n  |	 j d |  }	 d j d | d |	  }
 | d k	 ra|
 d j d	 | j d |   7}
 n  | j |
  q Wd
 j |  S(   s5   Provide an English sentence describing a missing arc.i    s    didn't jump to the function exits   didn't jump to line {lineno}Ri   s   line {start} {emsg}R/   t   emsgs   , because {smsg}t   smsgs    or N(   NN(   R(   R%   Rq   RF   t   missing_arc_descriptiont   formatt   appendt   join(   R)   R/   t   endt   executed_arcst   actual_startt   fragment_pairst   msgst   fragment_pairR   R~   t   msg(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR   7  s0    		%N(   t   __name__t
   __module__t   __doc__R   R%   R+   t   propertyR-   R=   R`   RU   Rc   Rd   Rh   Rp   Re   Rq   R}   R   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR      s   =		[									R,   c           B   sG   e  Z d  Z e d d  d d d   Z d   Z d   Z d   Z RS(   s3   Parse bytecode to understand the structure of code.R   t   unicodec         C   s   | |  _  | r | |  _ nN y t | | d  |  _ Wn2 t k
 rh } t d | | j | j f   n Xx5 d d g D]' } t |  j |  sv t d   qv qv Wd  S(   Nt   execu5   Couldn't parse '%s' as Python source: '%s' at line %dt	   co_lnotabt   co_firstlinenoss   This implementation of Python doesn't support code analysis.
Run coverage.py under another Python for this command.(	   R   t   codeR   t   SyntaxErrorR   R   Ri   Rl   R   (   R)   R   R   R   t   synerrt   attr(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR+   d  s    	c            s#   t    j  }   f d   | D S(   s~   Iterate over all the code objects nested within this one.

        The iteration includes `self` as its first value.

        c         3   s$   |  ] } t    j d  | Vq d S(   R   N(   R,   R   (   Rb   t   c(   R)   (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pys	   <genexpr>  s    (   R   R   (   R)   t   children(    (   R)   s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   child_parsers|  s    c         c   s   t  |  j j d d d   } t  |  j j d d d   } d } |  j j } d } xZ t | |  D]I \ } } | r | | k r | | f V| } n  | | 7} n  | | 7} qf W| | k r | | f Vn  d S(   s&  Map byte offsets to line numbers in `code`.

        Uses co_lnotab described in Python/compile.c to map byte offsets to
        line numbers.  Produces a sequence: (b0, l0), (b1, l1), ...

        Only byte offsets that correspond to line numbers are included in the
        results.

        i    Ni   i   (   R   R   R   R%   R   t   zip(   R)   t   byte_incrementst   line_incrementst   last_line_numt   line_numt   byte_numt	   byte_incrt	   line_incr(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _bytes_lines  s    	c         c   s=   x6 |  j    D]( } x | j   D] \ } } | Vq  Wq Wd S(   s   Find the statements in `self.code`.

        Produce a sequence of line numbers that start statements.  Recurses
        into all code objects reachable from `self.code`.

        N(   R   R   (   R)   t   bpR\   R_   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyRO     s    N(	   R   R   R   R   R%   R+   R   R   RO   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR,   a  s   			t	   LoopBlockc           B   s&   e  Z d  Z e d e  d    Z RS(   s@   A block on the block stack representing a `for` or `while` loop.R/   c         C   s   | |  _  t   |  _ d  S(   N(   R/   R   t   break_exits(   R)   R/   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR+     s    	(   R   R   R   R   R|   R+   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s   t   FunctionBlockc           B   s,   e  Z d  Z e d e d e  d    Z RS(   s>   A block on the block stack representing a function definition.R/   t   namec         C   s   | |  _  | |  _ d  S(   N(   R/   R   (   R)   R/   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR+     s    	(   R   R   R   R   R|   t   strR+   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s   t   TryBlockc           B   s,   e  Z d  Z e d d d d  d    Z RS(   s6   A block on the block stack representing a `try` block.t   handler_starts   int|Nonet   final_startc         C   sF   | |  _  | |  _ t   |  _ t   |  _ t   |  _ t   |  _ d  S(   N(   R   R   R   t
   break_fromt   continue_fromt   return_fromt
   raise_from(   R)   R   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR+     s    		(   R   R   R   R   R+   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s   t   ArcStartt   Arcs   lineno, causec           B   s   e  Z d  Z d d  Z RS(   s  The information needed to start an arc.

    `lineno` is the line number the arc starts from.

    `cause` is an English text fragment used as the `startmsg` for
    AstArcAnalyzer.missing_arc_fragments.  It will be used to describe why an
    arc wasn't executed, so should fit well into a sentence of the form,
    "Line 17 didn't run because {cause}."  The fragment can include "{lineno}"
    to have `lineno` interpolated into it.

    c         C   s   t  t |   j |  | |  S(   N(   t   superR   t   __new__(   t   clsRi   t   cause(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s    N(   R   R   R   R%   R   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s   t	   ArcStartsc         C   s   t  d   |  D  S(   Nc         s   s   |  ] } t  | t  Vq d  S(   N(   t
   isinstanceR   (   Rb   t   x(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pys	   <genexpr>  s    (   t   all(   t   seq(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   <lambda>  s    t   COVERAGE_AST_DUMPi    t   NodeListc           B   s   e  Z d  Z d   Z RS(   s   A synthetic fictitious node, containing a sequence of nodes.

    This is used when collapsing optimized if-statements, to represent the
    unconditional execution of one of the clauses.

    c         C   s   | |  _  | d j |  _ d  S(   Ni    (   t   bodyRi   (   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR+     s    	(   R   R   R   R+   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s   Rr   c           B   sk  e  Z d  Z e d d d e  d    Z d   Z d? d? d  Z d   Z	 e d e
  d	    Z d
   Z d   Z d   Z d   Z e d d d d d d d d d d d d g  Z e d d  d    Z e d  e d d  d? d? d    Z d   Z d   Z d    Z d!   Z e d" d  d#    Z e d" d  d$    Z e d" d  d%    Z e d" d  d&    Z e d d  d'    Z e d d  d(    Z e Z e d d  d)    Z e d d  d*    Z  e  Z! e Z" e Z# e d d  d+    Z$ e d d  d,    Z% e d d  d-    Z& e d d  d.    Z' e d d  d/    Z( e d0 d d" d d d  d1    Z) e d d  d2    Z* e d d  d3    Z+ e d d  d4    Z, e d d  d5    Z- e- Z. d6   Z/ d7   Z0 e0 Z1 d8   Z2 d9   Z3 e3 d:  Z4 e3 d;  Z5 e3 d<  Z6 e3 d=  Z7 e8 j9 rie3 d>  Z: n  RS(@   s>   Analyze source text with an AST to find executable code paths.R   R   R   c            s   t  j t |   |  _ t   f d   | D  |  _   |  _ t rx d j |  j  GHd j |  j  GHt	 |  j  n  t   |  _
 t j t  |  _ g  |  _ t t t j j d d    |  _ d  S(   Nc         3   s!   |  ] }   j  | |  Vq d  S(   N(   RF   (   Rb   R_   (   t	   multiline(    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pys	   <genexpr>  s    s   Statements: {0}s   Multiline map: {0}t   COVERAGE_TRACK_ARCSi    (   t   astt   parseR   t	   root_nodeR   R   R   t   AST_DUMPR   t   ast_dumpRe   Rz   R{   t   listRt   t   block_stackt   boolR|   t   ost   environRF   t   debug(   R)   R   R   R   (    (   R   s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR+     s    		c         C   s\   xU t  j |  j  D]A } | j j } t |  d | d  } | d k	 r | |  q q Wd S(   s   Examine the AST tree from `root_node` to determine possible arcs.

        This sets the `arcs` attribute to be a set of (from, to) line number
        pairs.

        t   _code_object__N(   R   t   walkR   t	   __class__R   t   getattrR%   (   R)   t   nodet	   node_namet   code_object_handler(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyRs     s
    c         C   s   |  j  r1 d j | | | |  GHt d d  GHn  |  j j | | f  | d k	 s_ | d k	 r |  j | | f j | | f  n  d S(   s@   Add an arc, including message fragments to use if it is missing.s!   
Adding arc: ({}, {}): {!r}, {!r}t   limiti   N(   R   R   R   Re   R6   R%   Rt   R   (   R)   R/   R   R   R~   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   add_arc#  s    	c         C   s   t  |  j  S(   s.   Yield the blocks in nearest-to-farthest order.(   t   reversedR   (   R)   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   nearest_blocks-  s    t   returnsc         C   sC   | j  j } t |  d | d  } | d k	 r8 | |  S| j Sd S(   s}   What is the right line number to use for this node?

        This dispatches to _line__Node functions where needed.

        t   _line__N(   R   R   R   R%   Ri   (   R)   R   R   t   handler(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   line_for_node1  s
    
c         C   s   |  j  | j  S(   N(   R   t   value(   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _line__Assign?  s    c         C   sU   t  j d k rJ | j rJ | j d d  k	 r9 | j d j S| j d j Sn | j Sd  S(   Ni   i   i    (   i   i   (   R    t	   PYVERSIONt   keysR%   Ri   t   values(   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _line__DictB  s
    c         C   s(   | j  r |  j | j  d  S| j Sd  S(   Ni    (   t   eltsR   Ri   (   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _line__ListN  s    	c         C   s%   | j  r |  j | j  d  Sd Sd  S(   Ni    i   (   R   R   (   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _line__ModuleT  s    	t   Assignt   Assertt	   AugAssignt   Deletet   Exect   Exprt   Globalt   Importt
   ImportFromt   Nonlocalt   Passt   PrintR   c         C   sX   | j  j } t |  d | d  } | d k	 r8 | |  St t |  j |   g  Sd S(   s  Add the arcs for `node`.

        Return a set of ArcStarts, exits from this node to the next. Because a
        node represents an entire sub-tree (including its children), the exits
        from a node can be arbitrarily complex::

            if something(1):
                if other(2):
                    doit(3)
                else:
                    doit(5)

        There are two exits from line 1: they start at line 3 and line 5.

        t	   _handle__N(   R   R   R   R%   R   R   R   (   R)   R   R   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   add_arcsa  s
    

s   from_start, prev_startsc         C   s   | d k r t | g  } n  x | D] } |  j |  } |  j j | |  } | |  j k r |  j |  } | d k r q% n  |  j |  } n  x' | D] } |  j | j | | j	  q W|  j
 |  } q% W| S(   su  Add arcs for the body of a compound statement.

        `body` is the body node.  `from_start` is a single `ArcStart` that can
        be the previous line in flow before this body.  `prev_starts` is a set
        of ArcStarts that can be the previous line.  Only one of them should be
        given.

        Returns a set of ArcStarts, the exits from this body.

        N(   R%   R   R   R   RF   R   t   find_non_missing_nodeR   Ri   R   R   (   R)   R   t
   from_startt   prev_startst	   body_nodeRi   RU   t
   prev_start(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   add_body_arcs  s    c         C   sr   |  j  |  } |  j j | |  } | |  j k r7 | St |  d | j j d  } | rh | |  } n d } | S(   s  Search `node` looking for a child that has not been optimized away.

        This might return the node you started with, or it will work recursively
        to find a child node in self.statements.

        Returns a node, or None if none of the node remains.

        t
   _missing__N(   R   R   RF   R   R   R   R   R%   (   R)   R   Ri   RU   t
   missing_fn(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR     s    c         C   sE   |  j  t | j   } | r" | S| j rA |  j  t | j   Sd  S(   N(   R   R   R   t   orelseR%   (   R)   R   t   non_missing(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _missing__If  s    	c         C   ss   g  } x< | j  D]1 } |  j |  } | d  k	 r | j |  q q W| sO d  St |  d k ri | d St |  S(   Ni   i    (   R   R   R%   R   t   lenR   (   R)   R   t   non_missing_childrent   child(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _missing__NodeList  s    c         C   sB   | j  j } | d k r d S| d k r> | j d	 k r> d Sn  d
 S(   s    Is this a compile-time constant?t   NameConstantt   Numt   NameRC   R"   R%   t	   __debug__(   R  R  (   s   Trues   Falses   Nones	   __debug__N(   R   R   t   idR%   (   R)   R   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   is_constant_expr  s    t   exitsc         C   sp   xi |  j    D][ } t | t  r6 | j j |  Pq t | t  r | j d k	 r | j j |  Pq q Wd S(   s0   Add arcs due to jumps from `exits` being breaks.N(	   R   R   R   R   RK   R   R   R%   R   (   R)   R  t   block(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   process_break_exits  s    c         C   s   x |  j    D]x } t | t  rS x* | D]" } |  j | j | j | j  q) WPq t | t  r | j d k	 r | j
 j |  Pq q Wd S(   s3   Add arcs due to jumps from `exits` being continues.N(   R   R   R   R   Ri   R/   R   R   R   R%   R   RK   (   R)   R  R  t   xit(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   process_continue_exits  s     c         C   s   x |  j    D] } t | t  r | j d k	 rb x* | D]" } |  j | j | j | j  q8 WPq | j d k	 r | j	 j
 |  Pq q t | t  r x: | D]2 } |  j | j | j | j d j | j   q WPq q Wd S(   s0   Add arcs due to jumps from `exits` being raises.s!   didn't except from function '{0}'N(   R   R   R   R   R%   R   Ri   R   R   R   RK   R   R/   R   R   (   R)   R  R  R
  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   process_raise_exits  s     c         C   s   x |  j    D] } t | t  rE | j d k	 rE | j j |  Pq t | t  r x: | D]2 } |  j | j	 | j
 | j d j | j   q[ WPq q Wd S(   s1   Add arcs due to jumps from `exits` being returns.s!   didn't return from function '{0}'N(   R   R   R   R   R%   R   RK   R   R   Ri   R/   R   R   R   (   R)   R  R  R
  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   process_return_exits  s    c         C   s8   |  j  |  } t | d d } |  j | g  t   S(   NR   s*   the break on line {lineno} wasn't executed(   R   R   R	  R   (   R)   R   t   heret   break_start(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__Break-  s    c         C   s   |  j  |  } | j r xE | j D]: } |  j  |  } | | k r" |  j | |  | } q" q" W|  j  | j d  } |  j j | |  } xF t | d |  D]. } | |  j k r |  j | |  | } q q Wn  t t	 |  g  S(   sB   Add arcs for things that can be decorated (classes and functions).i    i   (
   R   t   decorator_listR   R   R   RF   R   R   R   R   (   R)   R   t   lastt   dec_nodet	   dec_startt
   body_startRi   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle_decorated4  s    	c         C   s8   |  j  |  } t | d d } |  j | g  t   S(   NR   s-   the continue on line {lineno} wasn't executed(   R   R   R  R   (   R)   R   R  t   continue_start(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__ContinueM  s    c         C   s   |  j  | j  } |  j j t d |   t | d d } |  j | j d | } x' | D] } |  j | j	 | | j
  q\ W|  j j   } | j } t | d d } | j r |  j | j d | } | | O} n | j |  | S(   NR/   R   s'   the loop on line {lineno} never startedR   s)   the loop on line {lineno} didn't complete(   R   t   iterR   R   R   R   R   R   R   Ri   R   t   popR   R   R6   (   R)   R   R/   R   R  R
  t   my_blockt
   else_exits(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__ForT  s    		c         C   sn   |  j  | j  } t | d d } |  j | j d | } t | d d } | |  j | j d | O} | S(   NR   s-   the condition on line {lineno} was never trueR   s.   the condition on line {lineno} was never false(   R   t   testR   R   R   R   (   R)   R   R/   R   R  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__Ifm  s    c         C   s1   |  j  |  } |  j | j d t |  } | S(   NR   (   R   R   R   R   (   R)   R   R/   R  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__NodeListv  s    c         C   s8   |  j  |  } t | d d } |  j | g  t   S(   NR   s*   the raise on line {lineno} wasn't executed(   R   R   R  R   (   R)   R   R  t   raise_start(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__Raise|  s    c         C   s8   |  j  |  } t | d d } |  j | g  t   S(   NR   s+   the return on line {lineno} wasn't executed(   R   R   R  R   (   R)   R   R  t   return_start(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__Return  s    c         C   s  | j  r" |  j | j  d  } n d  } | j rJ |  j | j d  } n d  } t | |  } |  j j |  |  j |  } |  j | j d t	 |  } | j r d  | _
 | j  r t g   | _ q n |  j j   t   } | j  rpd  } x| | j  D]n }	 |  j |	  } | d  k	 r/|  j | |  n  | } d }
 t	 | d |
 } | |  j |	 j d | O} q Wn  | j r|  j | j d | } n  | | O} | j r|  j j   | | j B| j B| j B| j B} |  j | j d | } | j r|  j |  j | j |   n  | j r>|  j |  j | j |   n  | j rf|  j |  j | j |   n  | j r|  j |  j | j |   n  | r| } qn  | S(   Ni    R   s3   the exception caught by line {lineno} didn't happenR   R   (   t   handlersR   R%   t	   finalbodyR   R   R   R   R   R   R   R   R   R  R   R   R   R   R   R	  t   _combine_finally_startsR  R  R  (   R)   R   R   R   t	   try_blockR/   R  t   handler_exitst   last_handler_startt   handler_nodet
   from_causeR   t
   final_fromt   final_exits(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__Try  sb    							#	
	
				Ro   c            s}   g  } xE t  |  D]7 } | j d k	 r | j | j j d | j   q q Wd j |    t   f d   | D  } | S(   s  Helper for building the cause of `finally` branches.

        "finally" clauses might not execute their exits, and the causes could
        be due to a failure to execute any of the exits in the try block. So
        we use the causes from `starts` as the causes for `exits`.
        Ri   s    or c         3   s!   |  ] } t  | j    Vq d  S(   N(   R   Ri   (   Rb   R
  (   R   (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pys	   <genexpr>  s    N(   t   sortedR   R%   R   R   Ri   R   R   (   R)   Ro   R  t   causesR/   (    (   R   s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR'    s    &c         C   s   g  | _  |  j |  S(   N(   R&  R/  (   R)   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__TryExcept  s    	c         C   s   g  | _  g  | _ | j d } | j j d k r | j | j k r t | j  d k s^ t  | j | _ | j  | _  | j | _ n  |  j |  S(   Ni    t	   TryExcepti   (	   R%  R   R   R   R   Ri   R   R   R/  (   R)   R   t   first(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__TryFinally  s    		$c   
      C   sK  |  j  | j  } |  j | j  } } | r\ t j sC | d k r\ |  j | j d  } n  |  j j t d |   t	 | d d } |  j
 | j d | } x' | D] } |  j | j | | j  q Wt   } |  j j   } | j | j  t	 | d d } | j r1|  j
 | j d | }	 | |	 O} n | sG| j |  n  | S(   NR  i    R/   R   s-   the condition on line {lineno} was never trueR   s.   the condition on line {lineno} was never false(   R  R  R   R    t   PY3R   R   R   R   R   R   R   Ri   R   R   R  RK   R   R   R6   (
   R)   R   t   constant_testR/   t   to_topR   R  R
  R  R  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__While
  s&    		c         C   s1   |  j  |  } |  j | j d t |  } | S(   NR   (   R   R   R   R   (   R)   R   R/   R  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _handle__With"  s    c         C   s   |  j  |  } | j rh |  j | j d t |  } xP | D]# } |  j | j | | j d  q> Wn" |  j | |  |  j | |  d  S(   NR   s   didn't exit the module(   R   R   R   R   R   Ri   R   (   R)   R   R/   R  R
  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _code_object__Module*  s    	$c         C   sn   |  j  |  } |  j j t d | d | j   |  j | j d t |  } |  j |  |  j j	   d  S(   NR/   R   R   (
   R   R   R   R   R   R   R   R   R  R  (   R)   R   R/   R  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _code_object__FunctionDef5  s
    "c         C   s|   |  j  |  } |  j | |  |  j | j d t |  } x7 | D]/ } |  j | j | | j d j | j   qE Wd  S(   NR   s#   didn't exit the body of class '{0}'(	   R   R   R   R   R   Ri   R   R   R   (   R)   R   R/   R  R
  (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _code_object__ClassDef>  s    c            s     f d   } | S(   sF   A function to make methods for online callable _code_object__ methods.c            sY   |  j  |  } |  j | | d  d j   |   |  j | | d  d j   |   d  S(   Ns   didn't run the {0} on line {1}s!   didn't finish the {0} on line {1}(   R   R   R%   R   (   R)   R   R/   (   t   noun(    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _code_object__oneline_callableJ  s
    #
(    (   R>  R?  (    (   R>  s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _make_oneline_code_methodH  s    t   lambdas   generator expressions   dictionary comprehensions   set comprehensions   list comprehensionN(;   R   R   R   R   R   R+   Rs   R%   R   R   R|   R   R   R   R   R   t   OK_TO_DEFAULTR   R
   R   R   R   R   R  R	  R  R  R  R  R  t   _handle__ClassDefR  R  t   _handle__AsyncFort   _handle__FunctionDeft   _handle__AsyncFunctionDefR  R   R"  R$  R/  R'  R2  R5  R9  R:  t   _handle__AsyncWithR;  R<  t   _code_object__AsyncFunctionDefR=  R@  t   _code_object__Lambdat   _code_object__GeneratorExpt   _code_object__DictCompt   _code_object__SetCompR    R6  t   _code_object__ListComp(    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyRr     sn   	
					 						U$			
		t   ctxc         C   s4   |  d g  d i  t   g k p3 t |  t t t f  S(   s:   Is `value` simple enough to be displayed on a single line?N(    (   R%   R   R   R   R|   t   float(   R   (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   _is_simple_value`  s    c         C   s  d | } t  |  t j  s: d j | |  j j |   GHd St |  d d  } | d k	 rm d j |  j  } n d } d j | |  j j |  } g  t j	 |   D]$ \ } } | t
 k r | | f ^ q } | s d j |  GHnt |  d	 k r,t | d
 d	  r,| d
 \ }	 } d j | |	 |  GHn | GH| d }
 x | D] \ }	 } d j |
 |	  } t |  rd j | |  GHqBt  | t  rd j |  GHx | D] } t | | d  qWd j |
  GHqB| GHt | | d  qBWd j |  GHd S(   sh   Dump the AST for `node`.

        This recursively walks the AST, printing a readable version.

        t    s   {0}<{1} {2!r}>NRi   s    @ {0}t    s
   {0}<{1}{2}s   {0}>i   i    s   {0} {1}: {2!r}>s       s   {0}{1}:s	   {0} {1!r}s   {0} [i   s   {0}](   R   R   t   ASTR   R   R   R   R%   Ri   t   iter_fieldst   SKIP_DUMP_FIELDSR   RP  R   R   (   R   t   depthRP   Ri   t   linemarkt   headR   R   t   named_fieldst
   field_namet   next_indentt   prefixt   n(    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyR   g  s>    
&
(0   R   R   Rz   R   R2   RA   RD   t   coverageR    t   coverage.backwardR   R   R   t   coverage.bytecodeR   t   coverage.debugR   t   coverage.miscR   R   R   R	   R
   R   R   R   t   coverage.phystokensR   R   R   t   objectR   R,   R   R   R   t
   namedtupleR   R   R|   R   RF   R   R   Rr   RU  RP  R   (    (    (    s1   /tmp/pip-build-hU8Cw8/coverage/coverage/parser.pyt   <module>   s>   ( KP

"!  c		