
    V.j"                       d Z ddlmZ ddlZddl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  G d d	      Zdd
ZddZ eddd      Z edd      Z edd      Z G d d      Zeee   ee   f   Zeeef   Z	 	 	 	 	 	 ddZddZy)z!Bytecode analysis for coverage.py    )annotationsN)IterableMapping)CodeType)Optional)TArcTLineNoTOffsetc                  P    e Zd ZdZdddd	 	 	 	 	 	 	 d	dZd
dZddZddZddZy)
ByteParserz3Parse bytecode to understand the structure of code.N)codetextfilenamec               D    ||J t        ||xs ddd      }|| _        y )Nz<string>execT)dont_inherit)compiler   )selfr   r   r   s       SC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\coverage/bytecode.py__init__zByteParser.__init__   s1     <###4!7ZdSD	    c                0    d | j                         D        S )a|  Iterate over all the code objects nested within this one.

        The iteration includes `self` as its first value.

        We skip code objects named `__annotate__` since they are deferred
        annotations that usually are never run.  If there are errors in the
        annotations, they will be caught by type checkers or other tools that
        use annotations.

        c              3  T   K   | ]   }|j                   d k7  st        |       " yw)__annotate__)r   N)co_namer   ).0cs     r   	<genexpr>z,ByteParser._child_parsers.<locals>.<genexpr>+   s'     _,?q199P^C^
"",?s   (()code_objects)r   s    r   _child_parserszByteParser._child_parsers    s     `D,=,=,?__r   c              #     K   | j                   g}|rK|j                         }|j                  D ]$  }t        |t              s|j                  |       & | |rJyyw)z,Iterate over all the code objects in `code`.N)r   pop	co_consts
isinstancer   append)r   stackr   r   s       r   r   zByteParser.code_objects-   sP      99;D^^a*LLO $ J s   ?AAAc              #  `   K   | j                   j                         D ]  \  }}}|s
|  yw)zyYield the line numbers possible in this code object.

        Uses co_lines() to produce a sequence: l0, l1, ...
        N)r   co_lines)r   _lines      r   _line_numberszByteParser._line_numbers9   s-     
 )),,.JAq$
 /s   $..c              #  j   K   | j                         D ]  }|j                         E d{     y7 w)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+   )r   bps     r   find_statementszByteParser.find_statementsB   s0      %%'B''))) ()s   '313)r   zCodeType | Noner   
str | Noner   r/   returnNone)r0   zIterable[ByteParser])r0   zIterable[CodeType])r0   zIterable[TLineNo])	__name__
__module____qualname____doc__r   r    r   r+   r.    r   r   r   r      sR    =
 !%#
 
 	

 
 

`
	*r   r   c                p    i }| j                         D ]   \  }}}|
t        ||d      D ]  }|||<   	 " |S )z6Make a dict mapping byte code offsets to line numbers.   )r(   range)r   b2lbstartbendlinenoboffsets         r   bytes_to_linesr?   N   sG    
C $f q1%G 2 !0 Jr   c                     | D ch c]&  }t         j                  j                  |      x}s%|( }}|s
J d|         |S c c}w )zMake a set of opcodes from instruction names.

    The names might not exist in this version of Python, skip those if not.
    z At least one opcode must exist: )disopmapget)op_namesnameopopss       r   op_setrH   X   sO    
 #
B($SYY]]4-@'@r'@2(C
B=28*==3J Cs
   &A A JUMP_BACKWARDJUMP_BACKWARD_NO_INTERRUPTJUMP_FORWARDRETURN_VALUERETURN_GENERATORNOP	NOT_TAKENc                  2    e Zd ZdZddZddd	 	 	 	 	 d	dZy)
InstructionWalkera]  Utility to step through trails of instructions.

    We have two reasons to need sequences of instructions from a code object:
    First, in strict sequence to visit all the instructions in the object.
    This is `walk(follow_jumps=False)`.  Second, we want to follow jumps to
    understand how execution will flow: `walk(follow_jumps=True)`.
    c                    || _         i | _        d }t        j                  |      D ]  }|| j                  |j                  <    |J |j                  | _        y N)r   instsrA   get_instructionsoffset
max_offset)r   r   insts      r   r   zInstructionWalker.__init__   sU    	57
((.D&*DJJt{{# / ++r   r   Tstart_atfollow_jumpsc             #  *  K   t               }|}|| j                  dz   k  rq||v ry|j                  |       | j                  j	                  |      x}r%| |r|j
                  t        v r|j                  }j|dz  }|| j                  dz   k  rpyyw)z}
        Yield instructions starting from `start_at`.  Follow unconditional
        jumps if `follow_jumps` is true.
           r8   N)setrW   addrT   rC   opcodeALWAYS_JUMPSjump_target)r   rZ   r[   seenrV   rX   s         r   walkzInstructionWalker.walk   s      ut**~HHVzz~~f--t-
DKK<$?!--FaKF t**s   BBBN)r   r   r0   r1   )rZ   r
   r[   boolr0   zIterable[dis.Instruction])r2   r3   r4   r5   r   rd   r6   r   r   rQ   rQ   v   s0    	& &'T"6:	"r   rQ   c                0   	
 t        j                  d       }t               

j                  d      D ]  }|j                  s|j
                  t        v r#|j                  		2j                  		      		 	 	 	 	 	 d 	
fd}t        j                  t              } |||j                  dz           |||j                         |||j                  <   |j                         D ]#  \  }}|D ]  }||   |   j                  |        %  |S )a  
    Calculate branch trails for `code`.

    `multiline_map` maps line numbers to the first line number of a
    multi-line statement.

    Instructions can have a jump_target, where they might jump to next.  Some
    instructions with a jump_target are unconditional jumps (ALWAYS_JUMPS), so
    they aren't interesting to us, since they aren't the start of a branch
    possibility.

    Instructions that might or might not jump somewhere else are branch
    possibilities.  For each of those, we track a trail of instructions.  These
    are lists of instruction offsets, the next instructions that can execute.
    We follow the trail until we get to a new source line.  That gives us the
    arc from the original instruction's line to the new source line.

    c                 4    t        j                  t              S rS   )collectionsdefaultdictr^   r6   r   r   <lambda>zbranch_trails.<locals>.<lambda>   s    @W@WX[@\r   Fr[   c                   t               }d }j                  |d      D ]  }|j                  |j                         |j                  }|	j                  ||      }|r	|k7  r|} nC|j                  r|j                  t        vr n#|j                  t        v s|j                   } n || |f   j                  |       y t               | d <   y )NTrY   )r^   rd   r_   rV   line_numberrC   rb   r`   ra   RETURNSco_firstlinenoupdate)
trailsrZ   inst_offsetsto_lineinst2l2r   	from_lineiwalkermultiline_maps
         r   add_one_branch_trailz+branch_trails.<locals>.add_one_branch_trail   s    
 *-LG xdK  .&&>&**2r2B"	/ G&&ELL,L\\W,#222G L "	7+,33LA"utr   r8   )rZ   )rq   TBranchTrailsOneSourcerZ   r
   r0   r1   )rh   ri   rQ   rd   rb   r`   ra   rm   rC   r^   rV   itemsrp   )r   rx   
the_trailsrX   ry   rq   arcoffsetsrV   rv   rw   s   ``       @@r   branch_trailsr      s   , !, 7 78\ ]J%G%0;;,&$$	!%%i;		%*	%	% 	% 	%6 *5)@)@)EVdkkAo>Vd.>.>?"(
4;; #LLNLC!6"3'..w7 " +c 1j r   c                   i }t        |       }|j                  d      D ]]  }|j                  t        v r|j                  ||j
                  <   /|j                  t        v sB|j
                  dz   ||j
                  <   _ |S )zMake a map of unconditional bytecodes jumping to others.

    Only include bytecodes that do no work and go to another bytecode.
    Frk   r8   )rQ   rd   r`   ra   rb   rV   NOPS)r   jumpsrw   rX   s       r   always_jumpsr      sq    
 E%G%0;;,&!%!1!1E$++[[D !%qE$++	 1
 Lr   )r   r   r0   zdict[TOffset, TLineNo])rD   strr0   zset[int])r   r   rx   zMapping[TLineNo, TLineNo]r0   TBranchTrails)r   r   r0   zdict[TOffset, TOffset])r5   
__future__r   rh   rA   collections.abcr   r   typesr   typingr   coverage.typesr   r	   r
   r   r?   rH   ra   rn   r   rQ   dictr^   rz   r   r   r   r6   r   r   <module>r      s    ( "  
 -   1 1:* :*z    	& &R htnc'l:; W445M
M,M M`r   