o
    g^                     @  s  d 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mZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZm Z  dd
l!m"Z"m#Z# ddl$m%Z% ddl&m'Z'm(Z( G dd dZ)G dd dZ*G dd de+ddZ,G dd deZ-ee'eeee. ee. f  f Z/G dd dZ0G dd de0Z1G dd de0Z2G dd de0Z3G dd  d e0Z4G d!d" d"ej5Z6d+d'd(Z7G d)d* d*Z8dS ),zCode parsing for coverage.py.    )annotationsN)CodeType)castAnyCallableDictIterableListOptionalProtocolSequenceSetTuple)env)code_objects)short_stack)NoSource	NotPython)
join_regex	nice_pair)generate_tokens)TArcTLineNoc                   @  s   e Zd ZdZ			d1d2d	d
Zd3ddZd4ddZd5ddZd6ddZd7ddZ	d8d d!Z
d4d"d#Zd9d$d%Zd4d&d'Zd:d)d*Z	d;d<d/d0ZdS )=PythonParserzParse code to find executable lines, excluded lines, etc.

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

    NtextOptional[str]filenameexcludereturnNonec              
   C  s   |s|sJ d|pd| _ |dur|| _n'ddlm} z|| j | _W n ty; } ztd| j  d| |d}~ww || _| jd| _t	 | _
t	 | _t	 | _t	 | _t	 | _t	 | _d	| _i | _d| _d| _dS )
z
        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 string.

        z*PythonParser needs either text or filenamez<code>Nr   )get_python_sourcezNo source for code: 'z': 
F)r   r   coverage.pythonr    OSErrorr   r   splitlinesset
statementsexcludedraw_statementsraw_excludedraw_classdefsraw_docstringsshow_tokens
_multiline	_all_arcs_missing_arc_fragments)selfr   r   r   r    err r3   O/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/coverage/parser.py__init__&   s.   

zPythonParser.__init__regexesstrSet[TLineNo]c                 G  sH   t |}t|}t }t| jddD ]\}}||r!|| q|S )zFind 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.

           start)r   recompiler&   	enumerater%   searchadd)r1   r6   combinedregex_cmatchesiltextr3   r3   r4   lines_matchingf   s   


zPythonParser.lines_matchingc                 C  s  | j r
| | j | _tj}d}d}d}d}d}d}d}d}	| jdus$J t| j}
|
D ]\}}\}}\}}}| jrLtdt	j
||t||f||f  |tjkrV|d7 }n|tjkr`|d8 }n|tjkrp|dkro| j| n|tjkr|dkr|	dkr| jt||d p|}|s|r| j| |}d}d}n\|d	kr|r|| jv rd}|r| j| nF|d
v r|	d7 }	n=|dv r|	d8 }	n4|tjkr|tjkr| jt||d  n|tjkr|r||krt||d D ]}|| j|< qd}d}| r|t	jkrd}|s|}|r||krd}|r| j| d}|}q+|s4t| j| jd}| j|  tj j!rG| jrIt"| j| jd< dS dS dS )zwParse the source to find the interesting facts about its lines.

        A handful of attributes are updated.

        r   FTNz%10s %5s %-20r %rr9   class:@z([{z)]})r   )#r   rF   r*   tokenINDENTr   r   r-   printtokenizetok_namegetr   DEDENTNAMEr+   r@   OPintersectionrangeSTRINGr,   updateNEWLINEr.   stripCOMMENT
ByteParserr   r)   _find_statementsr   
PYBEHAVIORmodule_firstline_1min)r1   prev_toktypeindentexclude_indent	excludingexcluding_decorators
first_lineemptyfirst_on_linenestingtokgentoktypettextslineno_elinenorE   should_excludelbyte_parserr3   r3   r4   
_raw_parsev   s   











zPythonParser._raw_parselinenor   c                 C  s2   |dk r| j | |  }|S | j ||}|S )zAReturn the first line number of the statement including `lineno`.r   )r.   rO   )r1   rr   r3   r3   r4   rd      s
   zPythonParser.first_linelinenosIterable[TLineNo]c                       fdd|D S )zMap the line numbers in `linenos` to the correct first line of the
        statement.

        Returns a set of the first lines.

        c                   s   h | ]}  |qS r3   rd   .0ro   r1   r3   r4   	<setcomp>   s    z+PythonParser.first_lines.<locals>.<setcomp>r3   )r1   rs   r3   ry   r4   first_lines   s   zPythonParser.first_linesr%   c                 C  s
   |  |S )z)Implement `FileReporter.translate_lines`.)r{   )r1   r%   r3   r3   r4   translate_lines      
zPythonParser.translate_linesarcsIterable[TArc]	Set[TArc]c                   ru   )z(Implement `FileReporter.translate_arcs`.c                   s$   h | ]\}}  |  |fqS r3   rv   )rx   abry   r3   r4   rz     s   $ z.PythonParser.translate_arcs.<locals>.<setcomp>r3   )r1   r~   r3   ry   r4   translate_arcs   s   zPythonParser.translate_arcsc              
   C  s   z|    W n4 tjttfy: } z$t|dr|j}n|jd d }td| j	 d|jd d|  |d}~ww | 
| j| _| j| jB }| j| }| 
|| | _dS )zParse source text to find executable lines, excluded lines, etc.

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

        rr   r9   r   zCouldn't parse 'z' as Python source: z	 at line N)rq   rM   
TokenErrorIndentationErrorSyntaxErrorhasattrrr   argsr   r   r{   r*   r(   r,   r)   r'   )r1   r2   rr   ignorestartsr3   r3   r4   parse_source  s&   


zPythonParser.parse_sourcec                 C  s&   | j du r	|   | j dusJ | j S )zGet 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/   _analyze_astry   r3   r3   r4   r~     s   
zPythonParser.arcsc                 C  sj   t | j| j| j}|  t | _|jD ]\}}| |}| |}||kr.| j	||f q|j
| _dS )zkRun the AstArcAnalyzer and save its results.

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

        N)AstArcAnalyzerr   r)   r.   analyzer&   r/   r~   rd   r@   missing_arc_fragmentsr0   )r1   aaal1l2fl1fl2r3   r3   r4   r   (  s   

zPythonParser._analyze_astDict[TLineNo, int]c                 C  sv   t t}|  D ]\}}|dk rq	|| jv rq	|| jv rq	||  d7  < q	| jD ]}||v r8||  d8  < q*|S )zYGet a count of exits from that each line.

        Excluded lines are excluded.

        r   r9   )collectionsdefaultdictintr~   r(   r+   )r1   exit_countsr   r   ro   r3   r3   r4   r   :  s   



zPythonParser.exit_countsr;   endexecuted_arcsOptional[Iterable[TArc]]c           
      C  s  | j du r|   | j dusJ |}|r/|dk r/|| kr/||f|vr/||f| j v r/||}}| j ||fdg}g }|D ]D\}}|du r_|dk r]| |f| j v rZ| | |  S d}nd}|j|d}d| d| }	|dur||	d	|j|d 7 }	||	 q=d
|S )z5Provide an English sentence describing a missing arc.Nr   NNz didn't jump to the function exitzdidn't jump to line {lineno}rr   zline  z
, because  or )r0   r   rO   missing_arc_descriptionformatappendjoin)
r1   r;   r   r   actual_startfragment_pairsmsgssmsgemsgmsgr3   r3   r4   r   U  s2   


z$PythonParser.missing_arc_description)NNN)r   r   r   r   r   r   r   r   )r6   r7   r   r8   r   r   )rr   r   r   r   )rs   rt   r   r8   )r%   rt   r   r8   )r~   r   r   r   )r   r   )r   r   N)r;   r   r   r   r   r   r   r7   )__name__
__module____qualname____doc__r5   rF   rq   rd   r{   r|   r   r   r~   r   r   r   r3   r3   r3   r4   r      s$    
@

t

	




r   c                   @  s>   e Zd ZdZ		ddddZdddZdddZdddZdS )rZ   z3Parse bytecode to understand the structure of code.Nr   r7   codeOptional[CodeType]r   r   r   r   c              
   C  sr   || _ |d ur|| _d S |d usJ zt||ddd| _W d S  ty8 } ztd||j|jp/df |d }~ww )NexecT)dont_inheritz5Couldn't parse '%s' as Python source: '%s' at line %dr   )r   r   r=   r   r   r   rr   )r1   r   r   r   synerrr3   r3   r4   r5     s    
zByteParser.__init__Iterable[ByteParser]c                   s    fddt  jD S )z~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)rZ   r   )rx   cry   r3   r4   	<genexpr>  s    z+ByteParser.child_parsers.<locals>.<genexpr>)r   r   ry   r3   ry   r4   child_parsers  s   zByteParser.child_parsersrt   c           
      c  s    t | jdr| j D ]
\}}}|r|V  qdS | jjddd }| jjddd }d}| jj}d}t||D ]\}}	|rK||krG|V  |}||7 }|	dkrS|	d8 }	||	7 }q8||kra|V  dS dS )zYield the line numbers possible in this code object.

        Uses co_lnotab described in Python/compile.c to find the
        line numbers.  Produces a sequence: l0, l1, ...
        co_linesr   N   r9         )r   r   r   	co_lnotabco_firstlinenozip)
r1   rl   linebyte_incrementsline_incrementslast_line_numline_numbyte_num	byte_incr	line_incrr3   r3   r4   _line_numbers  s0   

zByteParser._line_numbersc                 c  s"    |   D ]	}| E dH  qdS )zFind 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   )r1   bpr3   r3   r4   r[     s   zByteParser._find_statementsr   )r   r7   r   r   r   r   r   r   )r   r   )r   rt   )r   r   r   r   r5   r   r   r[   r3   r3   r3   r4   rZ     s    

rZ   c                      s$   e Zd ZdZd
d fdd	Z  ZS )ArcStarta  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.

    Nrr   r   causer   r   c                   s   t  | ||S r   )super__new__)clsrr   r   	__class__r3   r4   r        zArcStart.__new__r   )rr   r   r   r   r   r   )r   r   r   r   r   __classcell__r3   r3   r   r4   r     s    r   Arczlineno, causec                   @  s    e Zd ZdZ		ddddZdS )	TAddArcFnz&The type for AstArcAnalyzer.add_arc().Nr;   r   r   r   r   r   r   r   c                 C  s   d S r   r3   r1   r;   r   r   r   r3   r3   r4   __call__  s   zTAddArcFn.__call__r   
r;   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r3   r3   r3   r4   r     s
    r   c                   @  s8   e Zd ZdZddd	Zdd
dZdddZdddZdS )Blocka;  
    Blocks need to handle various exiting statements in their own ways.

    All of these methods take a list of exits, and a callable `add_arc`
    function that they can use to add arcs if needed.  They return True if the
    exits are handled, or False if the search should continue up the block
    stack.
    exitsSet[ArcStart]add_arcr   r   boolc                 C     t )zProcess break exits.AssertionErrorr1   r   r   r3   r3   r4   process_break_exits     zBlock.process_break_exitsc                 C  r   )zProcess continue exits.r   r   r3   r3   r4   process_continue_exits  r   zBlock.process_continue_exitsc                 C     dS )zProcess raise exits.Fr3   r   r3   r3   r4   process_raise_exits     zBlock.process_raise_exitsc                 C  r   )zProcess return exits.Fr3   r   r3   r3   r4   process_return_exits  r   zBlock.process_return_exitsNr   r   r   r   r   r   )r   r   r   r   r   r   r   r   r3   r3   r3   r4   r     s    
	

r   c                   @  s.   e Zd ZdZdddZdddZdddZdS )	LoopBlockz@A block on the block stack representing a `for` or `while` loop.r;   r   r   r   c                 C  s   || _ t | _d S r   )r;   r&   break_exitsr1   r;   r3   r3   r4   r5     s   zLoopBlock.__init__r   r   r   r   r   c                 C  s   | j | dS NT)r   rV   r   r3   r3   r4   r     s   zLoopBlock.process_break_exitsc                 C  s    |D ]}||j | j|j qdS r   )rr   r;   r   r1   r   r   xitr3   r3   r4   r     s   z LoopBlock.process_continue_exitsNr;   r   r   r   r   )r   r   r   r   r5   r   r   r3   r3   r3   r4   r     s
    

r   c                   @  s.   e Zd ZdZddd	ZdddZdddZdS )FunctionBlockz>A block on the block stack representing a function definition.r;   r   namer7   r   r   c                 C  s   || _ || _d S r   r;   r   )r1   r;   r   r3   r3   r4   r5   !  s   
zFunctionBlock.__init__r   r   r   r   r   c                 C  ,   |D ]}||j | j |jd| j qdS )Nzdidn't except from function Trr   r;   r   r   r   r3   r3   r4   r   '     
z!FunctionBlock.process_raise_exitsc                 C  r   )Nzdidn't return from function Tr   r   r3   r3   r4   r   /  r   z"FunctionBlock.process_return_exitsN)r;   r   r   r7   r   r   r   )r   r   r   r   r5   r   r   r3   r3   r3   r4   r     s
    

r   c                   @  sB   e Zd ZdZdddZdddZdddZdddZdddZdS )TryBlockz6A block on the block stack representing a `try` block.handler_startOptional[TLineNo]final_startr   r   c                 C  s0   || _ || _t | _t | _t | _t | _d S r   )r   r   r&   
break_fromcontinue_from
raise_fromreturn_from)r1   r   r   r3   r3   r4   r5   :  s   zTryBlock.__init__r   r   r   r   r   c                 C     | j d ur| j| dS dS NTF)r   r   rV   r   r3   r3   r4   r   G     
zTryBlock.process_break_exitsc                 C  r   r   )r   r   rV   r   r3   r3   r4   r   M  r  zTryBlock.process_continue_exitsc                 C  sH   | j d ur|D ]}||j| j |j qdS | jd usJ | j| dS r   )r   rr   r   r   r   rV   r   r3   r3   r4   r   S  s   
zTryBlock.process_raise_exitsc                 C  r   r   )r   r   rV   r   r3   r3   r4   r   \  r  zTryBlock.process_return_exitsN)r   r   r   r   r   r   r   )	r   r   r   r   r5   r   r   r   r   r3   r3   r3   r4   r   8  s    



	r   c                   @  sP   e Zd ZdZdddZ	ddddZdddZdddZdddZdddZ	dS )	WithBlockz7A block on the block stack representing a `with` block.r;   r   r   r   c                 C  s.   t jjsJ || _t | _t | _t | _d S r   )r   r\   exit_through_withr;   r&   r   r   r   r   r3   r3   r4   r5   e  s
   zWithBlock.__init__Nr   r   r   r   from_setOptional[Set[ArcStart]]r   c                 C  s2   |D ]}||j | j|j q|dur|| dS )z*Helper to process the four kinds of exits.NT)rr   r;   r   rV   )r1   r   r   r  r   r3   r3   r4   _process_exitss  s
   
zWithBlock._process_exitsc                 C     |  ||| jS r   )r  r   r   r3   r3   r4   r     r   zWithBlock.process_break_exitsc                 C  r  r   )r  r   r   r3   r3   r4   r     r   z WithBlock.process_continue_exitsc                 C  s   |  ||S r   )r  r   r3   r3   r4   r        zWithBlock.process_raise_exitsc                 C  r  r   )r  r   r   r3   r3   r4   r     r   zWithBlock.process_return_exitsr   r   )r   r   r   r   r  r  r   r   r   )
r   r   r   r   r5   r  r   r   r   r   r3   r3   r3   r4   r  c  s    



r  c                   @  s   e Zd ZdZd	ddZdS )
NodeListzA 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.

    bodySequence[ast.AST]r   r   c                 C  s   || _ |d j| _d S Nr   )r
  rr   )r1   r
  r3   r3   r4   r5     s   zNodeList.__init__N)r
  r  r   r   )r   r   r   r   r5   r3   r3   r3   r4   r	    s    r	  nounr7   r   )Callable[[AstArcAnalyzer, ast.AST], None]c                   s   d
 fdd}|S )zPA function to make methods for expression-based callable _code_object__ methods.r1   r   nodeast.ASTr   r   c              	     sJ   |  |}| | |d d  d|  | || d d  d|  d S )Nzdidn't run the z	 on line zdidn't finish the )line_for_noder   )r1   r  r;   r  r3   r4   !_code_object__expression_callable  s   
"zG_make_expression_code_method.<locals>._code_object__expression_callableN)r1   r   r  r  r   r   r3   )r  r  r3   r  r4   _make_expression_code_method  s   r  c                   @  s  e Zd ZdZdd
dZdddZ		ddddZdddZdddZddd Z	dd"d#Z
e	Zdd%d&Ze	Ze	Zdd(d)Zdd+d,Zh d-Zdd/d0Z		ddd7d8Zdd:d;Zdd=d>Zdd@dAZddCdDZddEdFZddHdIZddJdKZddLdMZddNdOZddQdRZddSdTZeZddVdWZ ddYdZZ!e!Z"eZ#eZ$dd[d\Z%e&j'd]krdd_d`Z(ddadbZ)ddddeZ*ddgdhZ+ddjdkZ,ddmdnZ-ddodpZ.ddrdsZ/e/Z0ddtduZ1ddvdwZ2e2Z3ddydzZ4e5d{Z6e5d|Z7e8j9j:re5d}Z;e5d~Z<e5dZ=dS dS )r   z>Analyze source text with an AST to find executable code paths.r   r7   r'   r8   	multilineDict[TLineNo, TLineNo]r   r   c                   s   t || _ fdd|D | _ | _tttdd}|rHt	d| j  t	d| j  i }t
jdkr:d|d	< t	t j| jfd
di| t | _tt| _g | _tttdd| _d S )Nc                   s   h | ]}  ||qS r3   )rO   rw   r  r3   r4   rz         z*AstArcAnalyzer.__init__.<locals>.<setcomp>COVERAGE_AST_DUMP0zStatements: zMultiline map: )   	      r`   include_attributesTCOVERAGE_TRACK_ARCS)astparse	root_noder'   r  r   r   osgetenvrL   sysversion_infodumpr&   r~   r   r   listr   block_stackdebug)r1   r   r'   r  dump_astdumpkwr3   r  r4   r5     s   
zAstArcAnalyzer.__init__c                 C  s>   t | jD ]}|jj}t| d| d}|dur|| qdS )zExamine 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.

        _code_object__N)r   walkr"  r   r   getattr)r1   r  	node_namecode_object_handlerr3   r3   r4   r     s   zAstArcAnalyzer.analyzeNr;   r   r   r   r   r   c              	   C  sp   | j rtd| d| d|d| tt  | j||f |dus(|dur6| j||f ||f dS dS )z@Add an arc, including message fragments to use if it is missing.z
Adding possible arc: (z, z): N)r*  rL   r   r~   r@   r   r   r   r3   r3   r4   r     s    
zAstArcAnalyzer.add_arcIterable[Block]c                 C  s
   t | jS )z.Yield the blocks in nearest-to-farthest order.)reversedr)  ry   r3   r3   r4   nearest_blocks  r}   zAstArcAnalyzer.nearest_blocksr  r  c                 C  sD   |j j}ttttjgtf  t| d| d}|dur||S |j	S )z}What is the right line number to use for this node?

        This dispatches to _line__Node functions where needed.

        _line__N)
r   r   r   r
   r   r   ASTr   r/  rr   r1   r  r0  handlerr3   r3   r4   r    s   zAstArcAnalyzer.line_for_nodeast.FunctionDefc                 C  s    |j r|j d j}|S |j}|S )zSCompute first line number for things that can be decorated (classes and functions).r   )decorator_listrr   )r1   r  rr   r3   r3   r4   _line_decorated  s
   zAstArcAnalyzer._line_decorated
ast.Assignc                 C  s   |  |jS r   )r  valuer1   r  r3   r3   r4   _line__Assign  r  zAstArcAnalyzer._line__Assignast.Dictc                 C  s2   |j r|j d d ur|j d jS |jd jS |jS r  )keysrr   valuesr>  r3   r3   r4   _line__Dict  s
   zAstArcAnalyzer._line__Dictast.Listc                 C  s   |j r| |j d S |jS r  )eltsr  rr   r>  r3   r3   r4   _line__List  s   zAstArcAnalyzer._line__List
ast.Modulec                 C  s&   t jjrdS |jr| |jd S dS Nr9   r   )r   r\   r]   r
  r  r>  r3   r3   r4   _line__Module  s
   zAstArcAnalyzer._line__Module>   ExprPassAssertAssignDeleteGlobalImportNonlocal	AnnAssign	AugAssign
ImportFromr   c                 C  sp   |j j}ttttjgtt f  t	| d| d}|dur!||S t
jr0|| jvr0td| t| |hS )a  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.

        	_handle__Nz*** Unhandled: )r   r   r   r
   r   r   r6  r   r   r/  r   TESTINGOK_TO_DEFAULTRuntimeErrorr  r7  r3   r3   r4   add_arcs.  s   
zAstArcAnalyzer.add_arcsr
  r  
from_startOptional[ArcStart]prev_startsr  c           	      C  s   |du r|dus
J |h}|D ]7}|  |}| j||}|| jvr3| |}|du r,q|}|  |}|D ]}| |j||j q5| |}q|S )au  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  rO   r'   find_non_missing_noder   rr   r   rY  )	r1   r
  rZ  r\  	body_noderr   rd   maybe_body_node
prev_startr3   r3   r4   add_body_arcsO  s    



zAstArcAnalyzer.add_body_arcsOptional[ast.AST]c                 C  sr   |  |}| j||}|| jv r|S ttttjgttj f  t	| d|j
j d}|dur5||}|S d}|S )a  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.

        
_missing__N)r  r  rO   r'   r   r
   r   r   r6  r/  r   r   )r1   r  rr   rd   
missing_fnret_noder3   r3   r4   r]  p  s   

z$AstArcAnalyzer.find_non_missing_nodeast.Ifc                 C  s2   |  t|j}|r|S |jr|  t|jS d S r   )r]  r	  r
  orelse)r1   r  non_missingr3   r3   r4   _missing__If  s   zAstArcAnalyzer._missing__Ifr	  c                 C  sP   g }|j D ]}| |}|d ur|| q|sd S t|dkr$|d S t|S rH  )r
  r]  r   lenr	  )r1   r  non_missing_childrenchildmaybe_childr3   r3   r4   _missing__NodeList  s   


z!AstArcAnalyzer._missing__NodeList	ast.Whilec                 C  sd   |  t|j}|sd S t }|j|_t |_|j|j_d|j_t	|ds)J |j|_g |_
|S )NTruer
  )r]  r	  r
  r   Whilerr   Nametestidr   rg  )r1   r  
body_nodes	new_whiler3   r3   r4   _missing__While  s   

zAstArcAnalyzer._missing__Whilec                 C  s2   |j j}|dv r
dS t|tjr|jdv rdS dS )z Is this a compile-time constant?)ConstantNameConstantNumrz  )rp  Falser   	__debug__rr  N)r   r   
isinstancer   rr  rt  )r1   r  r0  r3   r3   r4   is_constant_expr  s   
zAstArcAnalyzer.is_constant_exprr   c                 C  &   |   D ]}||| jr dS qdS )z0Add arcs due to jumps from `exits` being breaks.N)r4  r   r   r1   r   blockr3   r3   r4   r     
   z"AstArcAnalyzer.process_break_exitsc                 C  r  )z3Add arcs due to jumps from `exits` being continues.N)r4  r   r   r  r3   r3   r4   r     r  z%AstArcAnalyzer.process_continue_exitsc                 C  r  )z0Add arcs due to jumps from `exits` being raises.N)r4  r   r   r  r3   r3   r4   r     r  z"AstArcAnalyzer.process_raise_exitsc                 C  r  )z1Add arcs due to jumps from `exits` being returns.N)r4  r   r   r  r3   r3   r4   r     r  z#AstArcAnalyzer.process_return_exits	ast.Breakc                 C  (   |  |}t|dd}| |h t S )Nz*the break on line {lineno} wasn't executedr   )r  r   r   r&   )r1   r  herebreak_startr3   r3   r4   _handle__Break     
zAstArcAnalyzer._handle__Breakc           
      C  s  |j }|j }|j}|r{d}|D ]}| |}|dur$||kr$| || |}q|dus-J | || |}tjjrit||dd D ]\}}| | || | qB| | |d | | || |d  |jr{| |jd }	| j	
|	|	}	|dusJ t|hS )zBAdd arcs for things that can be decorated (classes and functions).Nr9   r   )rr   r:  r  r   r   r\   trace_decorator_line_againr   r
  r  rO   r   )
r1   r  	main_linelastdecsdec_node	dec_starttopbot
body_startr3   r3   r4   _handle_decorated  s.   

z AstArcAnalyzer._handle_decoratedast.Continuec                 C  r  )Nz-the continue on line {lineno} wasn't executedr  )r  r   r   r&   )r1   r  r  continue_startr3   r3   r4   _handle__Continue  r  z AstArcAnalyzer._handle__Continueast.Forc                 C  s   |  |j}| jt|d t|dd}| j|j|d}|D ]}| |j	||j
 q| j }t|ts7J |j}t|dd}|jrQ| j|j|d}||O }|S || |S )Nr:   z'the loop on line {lineno} never startedr  rZ  z)the loop on line {lineno} didn't complete)r  iterr)  r   r   r   ra  r
  r   rr   r   popr}  r   rg  r@   )r1   r  r;   rZ  r   r   my_block
else_exitsr3   r3   r4   _handle__For%  s    

zAstArcAnalyzer._handle__Forc                 C  sL   |  |j}t|dd}| j|j|d}t|dd}|| j|j|dO }|S )N-the condition on line {lineno} was never truer  r  .the condition on line {lineno} was never false)r  rs  r   ra  r
  rg  )r1   r  r;   rZ  r   r3   r3   r4   _handle__If>  s   zAstArcAnalyzer._handle__If)r  
   	ast.Matchc           
      C  s   |  |}|}t }d}|jD ]=}|  |j}|j}t|tjr+|jd }t|tjs t|tjr3d}| 	||d t
|dd}	|| j|j|	dO }|}q|sT||	 |S )NFr  Tz+the pattern on line {lineno} always matchedz*the pattern on line {lineno} never matchedr  r  )r  r&   casespatternr}  r   MatchOrpatternsMatchAsr   r   ra  r
  r@   )
r1   r  r;   
last_startr   had_wildcardcase
case_startr  rZ  r3   r3   r4   _handle__MatchG  s,   



zAstArcAnalyzer._handle__Matchc                 C  s"   |  |}| j|jt|d}|S )Nr  )r  ra  r
  r   r1   r  r;   r   r3   r3   r4   _handle__NodeList^  s   
z AstArcAnalyzer._handle__NodeList	ast.Raisec                 C  r  )Nz*the raise on line {lineno} wasn't executedr  )r  r   r   r&   )r1   r  r  raise_startr3   r3   r4   _handle__Raisec     
zAstArcAnalyzer._handle__Raise
ast.Returnc                 C  r  )Nz+the return on line {lineno} wasn't executedr  )r  r   r   r&   )r1   r  r  return_startr3   r3   r4   _handle__Returnj  r  zAstArcAnalyzer._handle__Returnast.Tryc                 C  s  |j r| |j d }nd }|jr| |jd }nd }|d us&|d us&J t||}| j| | |}| j|jt|d}|jrNd |_	|j rMt
 |_n| j  t
 }|j rd }|j D ]%}	| |	}|d uro| || |}d}
t||
d}|| j|	j|dO }q^|jr| j|j|d}||O }|jrh| j  ||jB |jB |jB |jB }| j|j|d}|jrtjjr|jD ]}|j}|jj|d}|D ]
}| |j|| qq|j}n| |j|}| | |jrtjjr|jD ]}|j}|jj|d}|D ]}| |j|| q q|j}n| |j|}| | |jr+| | |j| |jrctjjrW|jD ]}|j}|jj|d}|D ]}| |j|| qEq7|j}n| |j|}| | |rh|}|S )Nr   r  z3the exception caught by line {lineno} didn't happenr  )r\  r   )handlersr  	finalbodyr   r)  r   ra  r
  r   r   r&   r   r  r   rg  r   r   r   r   r\   finally_jumps_backrr   r   r   _combine_finally_startsr   r   r   r   )r1   r  r   r   	try_blockr;   r   handler_exitslast_handler_starthandler_node
from_causerZ  
final_fromfinal_exits
break_linerr   r   
final_exitbreakscontinue_line	continuesreturn_linereturnsr3   r3   r4   _handle__Tryq  s   













zAstArcAnalyzer._handle__Tryr   c                   sR   g }t |D ]}|jdur||jj|jd qd|  fdd|D }|S )a  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`.
        Nr   r   c                   s   h | ]}t |j qS r3   )r   rr   )rx   r   r  r3   r4   rz     r  z9AstArcAnalyzer._combine_finally_starts.<locals>.<setcomp>)sortedr   r   r   rr   r   )r1   r   r   causesr;   r3   r  r4   r    s   

z&AstArcAnalyzer._combine_finally_startsc                 C  s   |  |j }}| |j}d}|rd}tjjrd}|r$|  |jd }| jt	|d t
|dd}| j|j|d}|D ]}| |j||j q=t }| j }	t|	t	sXJ ||	j t
|dd}|jru| j|j|d}
||
O }|S |s||| |S )	NFTr   r:   r  r  r  r  )r  rs  r~  r   r\   keep_constant_testr
  r)  r   r   r   ra  r   rr   r   r&   r  r}  rV   r   rg  r@   )r1   r  r;   to_topconstant_testtop_is_body0rZ  r   r   r  r  r3   r3   r4   _handle__While  s4   

zAstArcAnalyzer._handle__Whileast.Withc                 C  s   |  |}tjjr| jt|d | j|jt	|d}tjjrh| j
 }t|ts,J t	|h}|rA|D ]	}| |j| q5|}|jrN| | |j| |jr[| | |j| |jrh| | |j| |S )Nr:   r  )r  r   r\   r  r)  r   r  ra  r
  r   r  r}  r   rr   r   r   r  r   r   r   r   )r1   r  r;   r   
with_block	with_exitr   r3   r3   r4   _handle__With  s2   


zAstArcAnalyzer._handle__Withc                 C  sj   |  |}|jr%| j|jt| d}|D ]}| |j| |jd qd S | | | | ||  d S )Nr  zdidn't exit the module)r  r
  ra  r   r   rr   r   r1   r  r;   r   r   r3   r3   r4   _code_object__Module.  s   
z#AstArcAnalyzer._code_object__Modulec                 C  sN   |  |}| jt||jd | j|jt| d}| | | j	  d S )Nr   r  )
r  r)  r   r   r   ra  r
  r   r   r  r  r3   r3   r4   _code_object__FunctionDef9  s
   

z(AstArcAnalyzer._code_object__FunctionDefast.ClassDefc                 C  sX   |  |}| | | | j|jt|d}|D ]}| |j| |jd|j qd S )Nr  zdidn't exit the body of class )r  r   ra  r
  r   rr   r   r   r  r3   r3   r4   _code_object__ClassDefB  s   

z%AstArcAnalyzer._code_object__ClassDeflambdazgenerator expressionzdictionary comprehensionzset comprehensionzlist comprehension)r   r7   r'   r8   r  r  r   r   r   r   r   )r   r2  )r  r  r   r   )r  r9  r   r   )r  r<  r   r   )r  r@  r   r   )r  rD  r   r   )r  rG  r   r   )r  r  r   r   )r
  r  rZ  r[  r\  r  r   r   )r  r  r   rb  )r  rf  r   rb  )r  r	  r   rb  )r  ro  r   rb  )r  r  r   r   )r   r   r   r   )r  r  r   r   )r  r9  r   r   )r  r  r   r   )r  r  r   r   )r  rf  r   r   )r  r  r   r   )r  r	  r   r   )r  r  r   r   )r  r  r   r   )r  r  r   r   )r   r   r   r   r   r   )r  ro  r   r   )r  r  r   r   )r  rG  r   r   )r  r9  r   r   )r  r  r   r   )>r   r   r   r   r5   r   r   r4  r  r;  r?  _line__ClassDefrC  _line__FunctionDef_line__AsyncFunctionDefrF  rI  rW  rY  ra  r]  ri  rn  rw  r~  r   r   r   r   r  r  _handle__ClassDefr  r  _handle__AsyncFor_handle__FunctionDef_handle__AsyncFunctionDefr  r%  r&  r  r  r  r  r  r  r  r  _handle__AsyncWithr  r  _code_object__AsyncFunctionDefr  r  _code_object__Lambda_code_object__GeneratorExpr   r\   comprehensions_are_functions_code_object__DictComp_code_object__SetComp_code_object__ListCompr3   r3   r3   r4   r     sz    

%








$
!
"


















o





r   )r  r7   r   r  )9r   
__future__r   r   r   r#  r<   r%  rJ   rM   typesr   typingr   r   r   r   r   r	   r
   r   r   r   r   coverager   coverage.bytecoder   coverage.debugr   coverage.exceptionsr   r   coverage.miscr   r   coverage.phystokensr   coverage.typesr   r   r   rZ   
namedtupler   r   r7   TArcFragmentsr   r   r   r   r  r6  r	  r  r   r3   r3   r3   r4   <module>   sB   4  fN +*
	