
    MhK                     "   d dl Z d dl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 d dl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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$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-  edde.fde.fdefg          Z/de/_0         edde.fde1fde2fg          Z3de3_0         G d de          Z4 G d d edde2fdee j5                 fdefg                    Z6 G d dej7                  Z7 G d  d!          Z8 G d" d#e9          Z: e:            Z; G d$ d%          Z< G d& d'e9          Z=d(ee/         d)ee/geee2e2f                  f         d*ee3         fd+Z>d, Z? G d- d.          Z@ G d/ d0e9          ZAdS )1    N)defaultdictCounter)Enum)dedent)	FrameTypeCodeTypeTracebackType)
IteratorListTupleOptional
NamedTupleAnyIterableCallableUnionSequence)Mapping)Token)only)	Evaluatoris_expression_interesting)truncateunique_in_order
line_rangeframe_and_lineno
iter_stackcollapse_repeatedgroup_by_key_funccached_propertyis_frame_pygmented_with_rangesassert_RangeInLinestartenddataz
Represents a range of characters within one line of source code,
and some associated data.

Typically this will be converted to a pair of markers by markers_from_ranges.
MarkerInLinepositionis_startstringa  
A string that is meant to be inserted at a given position in a line of source code.
For example, this could be an ANSI code or the opening or closing of an HTML tag.
is_start should be True if this is the first of a pair such as the opening of an HTML tag.
This will help to sort and insert markers correctly.

Typically this would be created from a RangeInLine by markers_from_ranges.
Then use Line.render to insert the markers correctly.
c                       e Zd ZdZdZdZdZdS )
BlankLinesaE  The values are intended to correspond to the following behaviour:
    HIDDEN: blank lines are not shown in the output
    VISIBLE: blank lines are visible in the output
    SINGLE: any consecutive blank lines are shown as a single blank line
            in the output. This option requires the line number to be shown.
            For a single blank line, the corresponding line number is shown.
            Two or more consecutive blank lines are shown as a single blank
            line in the output with a custom string shown instead of a
            specific line number.
             N)__name__
__module____qualname____doc__HIDDENVISIBLESINGLE     O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/stack_data/core.pyr-   r-   2   s)        	 	 FGFFFr9   r-   c                   .    e Zd ZdZej        Zej        ZdS )Variablear  
    An expression that appears one or more times in source code and its associated value.
    This will usually be a variable but it can be any expression evaluated by pure_eval.
    - name is the source text of the expression.
    - nodes is a list of equivalent nodes representing the same expression.
    - value is the safely evaluated value of the expression.
    N)r1   r2   r3   r4   object__hash____eq__r8   r9   r:   r<   r<   A   s(          H]FFFr9   r<   	_Variablenamenodesvaluec                       e Zd ZdZedee         fd            Zedee	ee
         f         fd            Zdee         fdZdej        de	de	deee	e	f                  fd	Zd
ej        dee	e	f         fdZdS )Sourcea  
    The source code of a single file and associated metadata.

    In addition to the attributes from the base class executing.Source,
    if .tree is not None, meaning this is valid Python code, objects have:
        - pieces: a list of Piece objects
        - tokens_by_lineno: a defaultdict(list) mapping line numbers to lists of tokens.

    Don't construct this class. Get an instance from frame_info.source.
    returnc                     | j         s/d t          dt          | j                  dz             D             S t	          |                                           S )Nc                 4    g | ]}t          ||d z             S r.   )range).0is     r:   
<listcomp>z!Source.pieces.<locals>.<listcomp>a   s4        aQ  r9   r.   )treerJ   lenlineslist_clean_piecesselfs    r:   pieceszSource.pieces^   s`    y 	 q#dj//A"566    D&&(()))r9   c                 ~    | j         st          d          t          |                                 j        d           S )NzJThis file doesn't contain valid Python, so .tokens_by_lineno doesn't existc                     | j         d         S Nr   )r%   )toks    r:   <lambda>z)Source.tokens_by_lineno.<locals>.<lambda>m   s    	! r9   )rN   AttributeErrorr   	asttokenstokensrS   s    r:   tokens_by_linenozSource.tokens_by_linenog   sD    y 	o !mnnn NN#$$
 
 	
r9   c           	   #      K                          j        dt           j                  dz             }d |D             }|d d         }|dd          D ]T\  }}|d         \  }}||k     r'||dz
  k    sJ d j        |dz
           v sJ ||f|d<   =|                    ||f           U|}d |dd          D             }d |d d         D             }||k    rNt          t          t          t          ||                              }	d |	D             }
t          d|
z             fd	}|D ]Y\  }} ||          r|dz  } ||           ||dz
            r|dz  } ||dz
            ||k     rt          ||          V  Zd S )
Nr.   c                 (    g | ]\  }}||k    ||fS r8   r8   rK   r%   r&   s      r:   rM   z(Source._clean_pieces.<locals>.<listcomp>r   s1     
 
 
U{{ CL{{r9   ;c                     g | ]\  }}|S r8   r8   ra   s      r:   rM   z(Source._clean_pieces.<locals>.<listcomp>   s    555JE3%555r9   c                     g | ]\  }}|S r8   r8   ra   s      r:   rM   z(Source._clean_pieces.<locals>.<listcomp>   s    222
s222r9   c                 8    g | ]}t          |          d k    |S rI   )rO   )rK   ss     r:   rM   z(Source._clean_pieces.<locals>.<listcomp>   s#    999c!ffqjj!jjjr9   zPieces mismatches: %sc                 n    	 j         | dz
                                            S # t          $ r Y dS w xY w)Nr.   F)rP   strip
IndexError)rL   rT   s    r:   is_blankz&Source._clean_pieces.<locals>.is_blank   sJ    :a!e,224444   uus   "& 
44)_raw_split_into_piecesrN   rO   rP   appendrQ   mapsetzipAssertionErrorrJ   )rT   rU   
new_piecesr%   r&   
last_startlast_endstartsendsjoins
mismatchesrk   s   `           r:   rR   zSource._clean_piecesp   s0     ,,TY3tz??Q;NOO
 
 &
 
 
 BQBZ
"122J 	0 	0LUC%/^"Zx1,,,,dj33333",c!2
2!!5#,////55&*55522fSbSk222T>>S#fd"3"34455E99U999J !8:!EFFF	 	 	 	 	 ! 	( 	(JE3(5// 
 (5// (37## q (37## s{{E3'''''	( 	(r9   stmtr%   r&   c              #     K   t          j        |          D ]\  }}t          |t                    r|rt          |d         t           j        t           j        t          t           dd          f          rpt          t          || j	                  
                                          D ];\  }}|d         } | j        |g|R  D ]\  }	}
||	k     r||	fV  |	|
k     r|	|
fV  |
} <||fV  d S )Nr   
match_caser8   )astiter_fields
isinstancerQ   ry   ExceptHandlergetattrsortedr   r   itemsrl   )rT   ry   r%   r&   rA   bodyranggroupsub_stmtinner_start	inner_ends              r:   rl   zSource._raw_split_into_pieces   s5      /$// 	* 	*JD$tT***/3*tAw33DgcS_acFdFd(eff* $**;D$/*R*R*X*X*Z*Z#[#[ * *KD%$QxH2M$2Mh2^Y]2^2^2^ * *.Y ;.."'"4444&22"-y"8888 )* Sjr9   nodec                 F    t          |                                 |          S N)r   asttext)rT   r   s     r:   r   zSource.line_range   s    $,,..$///r9   N)r1   r2   r3   r4   r    r   rJ   rU   r   intr   r^   r
   rR   r|   ASTr   rl   r   r8   r9   r:   rE   rE   R   s       	 	 *U * * * _* 
'#tE{*:"; 
 
 
 _
)(x )( )( )( )(V'  	
 
%S/	"   ,0sw 05c? 0 0 0 0 0 0r9   rE   c            	       J    e Zd ZdZdddddej        dded	ed
edefdZd Z	dS )Optionsa  
    Configuration for FrameInfo, either in the constructor or the .stack_data classmethod.
    These all determine which Lines and gaps are produced by FrameInfo.lines. 

    before and after are the number of pieces of context to include in a frame
    in addition to the executing piece.

    include_signature is whether to include the function signature as a piece in a frame.

    If a piece (other than the executing piece) has more than max_lines_per_piece lines,
    it will be truncated with a gap in the middle. 
    r0   r.   F   Nbeforeafterinclude_signaturemax_lines_per_piecepygments_formatterblank_linesr   r   r   r   c                Z    || _         || _        || _        || _        || _        || _        d S r   r   )rT   r   r   r   r   r   r   s          r:   __init__zOptions.__init__   s8     
!2#6 "4&r9   c                      t           j                  } fd|D             }d                    t                     j        d                    |                    S )Nc              3   Z   K   | ]%}d                      |j        |                   V  &dS )z{}={!r}N)format__dict__)rK   krT   s     r:   	<genexpr>z#Options.__repr__.<locals>.<genexpr>   s:      EE1!!!T]1%566EEEEEEr9   z{}({}), )r   r   r   typer1   join)rT   keysr   s   `  r:   __repr__zOptions.__repr__   sT    dm$$EEEEEEEtDzz2DIIe4D4DEEEr9   )
r1   r2   r3   r4   r-   r5   r   boolr   r   r8   r9   r:   r   r      s          &+'(#$+' ' '' '  $	'
 "%' ' ' ' F F F F Fr9   r   c                       e Zd ZdZd ZdS )LineGapaj  
    A singleton representing one or more lines of source code that were skipped
    in FrameInfo.lines.

    LINE_GAP can be created in two ways:
    - by truncating a piece of context that's too long.
    - immediately after the signature piece if Options.include_signature is true
      and the following piece isn't already part of the included pieces. 
    c                     dS )NLINE_GAPr8   rS   s    r:   r   zLineGap.__repr__   s    zr9   N)r1   r2   r3   r4   r   r8   r9   r:   r   r      s-             r9   r   c                   "    e Zd ZdZdedefdZdS )BlankLineRangez
    Records the line number range for blank lines gaps between pieces.
    For a single blank line, begin_lineno == end_lineno.
    begin_lineno
end_linenoc                 "    || _         || _        d S r   )r   r   )rT   r   r   s      r:   r   zBlankLineRange.__init__   s    ($r9   N)r1   r2   r3   r4   r   r   r8   r9   r:   r   r      s@         %S %c % % % % % %r9   r   c                   f   e Zd ZdZdddefdZd Zedefd            Z	ede
e         fd	            Zede
e         fd
            Zede
e         fd            Zede
e         fd            Zdde
e         fdZ	 ddej        dededee         fdZ	 ddddddee         dedededef
dZdS )Linea]  
    A single line of source code for a particular stack frame.

    Typically this is obtained from FrameInfo.lines.
    Since that list may also contain LINE_GAP, you should first check
    that this is really a Line before using it.

    Attributes:
        - frame_info
        - lineno: the 1-based line number within the file
        - text: the raw source of this line. For displaying text, see .render() instead.
        - leading_indent: the number of leading spaces that should probably be stripped.
            This attribute is set within FrameInfo.lines. If you construct this class
            directly you should probably set it manually (at least to 0).
        - is_current: whether this is the line currently being executed by the interpreter
            within this frame.
        - tokens: a list of source tokens in this line

    There are several helpers for constructing RangeInLines which can be converted to markers
    using markers_from_ranges which can be passed to .render():
        - token_ranges
        - variable_ranges
        - executing_node_ranges
        - range_from_node
    
frame_info	FrameInfolinenoc                 d    || _         || _        |j        j        |dz
           | _        d | _        d S )Nr.   )r   r   sourcerP   textleading_indent)rT   r   r   s      r:   r   zLine.__init__  s6    
 %%+FQJ7	"r9   c                 .    d                     |           S )Nzq<{self.__class__.__name__} {self.lineno} (current={self.is_current}) {self.text!r} of {self.frame_info.filename}>rS   r   rS   s    r:   r   zLine.__repr__  s    >>Df$f>O>O	Pr9   rF   c                 ,    | j         | j        j         k    S )zq
        Whether this is the line currently being executed by the interpreter
        within this frame.
        )r   r   rS   s    r:   
is_currentzLine.is_current  s     {do444r9   c                 :    | j         j        j        | j                 S )z
        A list of source tokens in this line.
        The tokens are Token objects from asttokens:
        https://asttokens.readthedocs.io/en/latest/api-index.html#asttokens.util.Token
        )r   r   r^   r   rS   s    r:   r]   zLine.tokens#  s     %6t{CCr9   c                 $    d | j         D             S )z
        A list of RangeInLines for each token in .tokens,
        where range.data is a Token object from asttokens:
        https://asttokens.readthedocs.io/en/latest/api-index.html#asttokens.util.Token
        c                 \    g | ])}t          |j        d          |j        d          |          *S rI   )r$   r%   r&   )rK   tokens     r:   rM   z%Line.token_ranges.<locals>.<listcomp>3  sI     
 
 
  A	! 
 
 
r9   )r]   rS   s    r:   token_rangeszLine.token_ranges,  s'    
 
 
 
 
 	
r9   c                 J      fd j         j         j                 D             S )a  
        A list of RangeInLines for each Variable that appears at least partially in this line.
        The data attribute of the range is a pair (variable, node) where node is the particular
        AST node from the list variable.nodes that corresponds to this range.
        c                 F    g | ]\  }}                     |||f          S r8   )range_from_node)rK   variabler   rT   s      r:   rM   z(Line.variable_ranges.<locals>.<listcomp>C  sB     
 
 
$   $'788
 
 
r9   )r   variables_by_linenor   rS   s   `r:   variable_rangeszLine.variable_ranges<  s:    
 
 
 
"&/"Edk"R
 
 
 	
r9   c                 @    |                      | j        j                  S )z
        A list of one or zero RangeInLines for the executing node of this frame.
        The list will have one element if the node can be found and it overlaps this line.
        )_raw_executing_node_rangesr   _executing_node_common_indentrS   s    r:   executing_node_rangeszLine.executing_node_rangesH  s$     ..O9
 
 	
r9   r   c                 h    | j         j        }|j        }|r|                     |||          }|r|gS g S r   )r   	executingr   r   )rT   common_indentexr   r   s        r:   r   zLine._raw_executing_node_rangesR  sF    _&w 	''b-@@D v	r9   r   r'   r   c                 H   | j         j                                        }|                    |d          \  \  }}\  }}|| j        cxk    r|k    sn dS || j        k    r|}|| j        k    rt          | j                  }||cxk    rdk    rn ndS t          |||          S )z
        If the given node overlaps with this line, return a RangeInLine
        with the correct start and end and the given data.
        Otherwise, return None.
        F)paddedNr   )r   r   r   get_text_positionsr   rO   r   r$   )	rT   r   r'   r   atextr%   range_startr&   	range_ends	            r:   r   zLine.range_from_node[  s     &..00161I1I$W\1I1]1]..sI++++++++4DK'K$+DII)((((q((((( 4;	4888r9   r8   TF)strip_leading_indent	pygmentedescape_htmlmarkersr   r   r   c                   |rv| j         j        rjt          | t          d                     | j         j        \  }}|| j        |z
           }|r)|                    | j        d| j                 dd          }|S | j        }t          |          t          t          |          dd          gz   }|                    d            g }	|r| j        }
nd	}
|
}|D ]k}||
|j                 }|rt          j        |          }|	                    |           |	                    |j                   t%          |j        |          }
ld                    |	          S )
a  
        Produces a string for display consisting of .text
        with the .strings of each marker inserted at the correct positions.
        If strip_leading_indent is true (the default) then leading spaces
        common to all lines in this frame will be excluded.
        z!Cannot use pygmented with markersN r.   Fr)   r*   r+   c                     | d d         S )Nr/   r8   )ts    r:   rZ   zLine.render.<locals>.<lambda>  s    1RaR5 r9   keyr   )r   scoper#   
ValueError_pygmented_scope_linesr   replacer   r   rQ   r(   rO   sortr)   htmlescaperm   r+   maxr   )rT   r   r   r   r   
start_linerP   resultr   partsr%   original_startmarker	text_parts                 r:   renderzLine.renderw  sq     	. 	K,O!P!PQQQ $ FJ4;34F# P	2F43F2F(GQOOMy w--<TU[]#^#^#^"__))) 	'EEE 	9 	9FU6?23I 3 K	22	LL###LL''' 88EEwwu~~r9   N)r   )r8   )r1   r2   r3   r4   r   r   r   propertyr   r   r   r   r]   r    r$   r   r   r   r   r|   r   r   r   r   r   r(   strr   r8   r9   r:   r   r      s        2### # # # #P P P 5D 5 5 5 X5 DU D D D XD 
d;/ 
 
 
 _
 	
k!2 	
 	
 	
 _	
 
tK'8 
 
 
 _
 T+=N     >?9 9G9#&97:9	+	9 9 9 9< /1- *.# %- - -l+- #'	-
 - - 
- - - - - -r9   r   ranges	converterrF   c                    g }| D ]} ||          }||\  }}t          |t                    rt          |t                    st          d          |t          |j        d|          t          |j        d|          gz  }|S )a  
    Helper to create MarkerInLines given some RangeInLines.
    converter should be a function accepting a RangeInLine returning
    either None (which is ignored) or a pair of strings which
    are used to create two markers included in the returned list.
    Nz1converter should return None or a pair of stringsTr   F)r~   r   	TypeErrorr(   r%   r&   )r   r   r   r   	convertedstart_string
end_strings          r:   markers_from_rangesr     s     G 
 
IdOO	#, j<-- 	Q*Z2M2M 	QOPPP$*tLQQQ$(U:NNN
 	
 Nr9   c                 x     ddl m} t           t                    r |             G  fdd           }|S )Nr   )get_style_by_namec                   p    e Zd ZdZi j         fdj                                        D             ZdS )+style_with_executing_node.<locals>.NewStyleTc                 2    i | ]\  }}|j         |d z   z   S ) )ExecutingNode)rK   r   vmodifiers      r:   
<dictcomp>z6style_with_executing_node.<locals>.NewStyle.<dictcomp>  s:       Aq S8!3  r9   N)r1   r2   r3   for_executing_nodestylesr   )r  styles   r:   NewStyler     s_        !
l
   !L..00  
r9   r  )pygments.stylesr   r~   r   )r  r  r   r  s   ``  r:   style_with_executing_noder	    sx    111111% )!!%((	
 	
 	
 	
 	
 	
 	
 	
5 	
 	
 	
 Or9   c                   |    e Zd ZdZdeeeef                  deee	e
f                  fdZedefd            Zd ZdS )	RepeatedFramesaZ  
    A sequence of consecutive stack frames which shouldn't be displayed because
    the same code and line number were repeated many times in the stack, e.g.
    because of deep recursion.

    Attributes:
        - frames: list of raw frame or traceback objects
        - frame_keys: list of tuples (frame.f_code, lineno) extracted from the frame objects.
                        It's this information from the frames that is used to determine
                        whether two frames should be considered similar (i.e. repeating).
        - description: A string briefly describing frame_keys
    frames
frame_keysc                 "    || _         || _        d S r   )r  r  )rT   r  r  s      r:   r   zRepeatedFrames.__init__  s    
 $r9   rF   c                     t          t          | j                                                  d           }d                    d |D                       S )zv
        A string briefly describing the repeated frames, e.g.
            my_function at line 10 (100 times)
        c                 :    | d          | d         d         j         fS )Nr.   r   )co_name)items    r:   rZ   z,RepeatedFrames.description.<locals>.<lambda>  s    47(DGAJ4F)G r9   r   r   c              3      K   | ]R\  \  }}}d                      t                              |j                                      |          ||          V  SdS )z'{name} at line {lineno} ({count} times))rA   r   countN)r   rE   for_filenameco_filenamecode_qualname)rK   coder   r  s       r:   r   z-RepeatedFrames.description.<locals>.<genexpr>  s}       
 
 &v 6<<(()9::HHNN =  
 
 
 
 
 
r9   )r   r   r  r   r   )rT   countss     r:   descriptionzRepeatedFrames.description  sm     006688GGI I Iyy 
 
 *0
 
 
 
 
 	
r9   c                 .    d                     |           S )Nz.<{self.__class__.__name__} {self.description}>rS   r   rS   s    r:   r   zRepeatedFrames.__repr__  s    ?FFDFQQQr9   N)r1   r2   r3   r4   r   r   r   r	   r   r   r   r   r    r   r  r   r8   r9   r:   r  r    s         %y-789% U8S=12% % % % 
S 
 
 
 _
 R R R R Rr9   r  c                      e Zd ZdZ	 ddeeef         dee         fdZ	d Z
e	 ddddeeef         dee         d	ed
eed ef                  fd            Zed
ee         fd            Zed
efd            Zed
efd            Zed
ee         fd            Zed
efd            Zed
eeeeef                  fd            Zed
eej                 fd            Z ed
ee!eee         f                  fd            Z"ed
ee#         fd            Z$ed
e%eee!e#ej        f                  f         fd            Z&ed
ee#         fd            Z'ed
ee#         fd            Z(dS )r   a  
    Information about a frame!
    Pass either a frame object or a traceback object,
    and optionally an Options object to configure.

    Or use the classmethod FrameInfo.stack_data() for an iterator of FrameInfo and
    RepeatedFrames objects. 

    Attributes:
        - frame: an actual stack frame object, either frame_or_tb or frame_or_tb.tb_frame
        - options
        - code: frame.f_code
        - source: a Source object
        - filename: a hopefully absolute file path derived from code.co_filename
        - scope: the AST node of the innermost function, class or module being executed
        - lines: a list of Line/LineGap objects to display, determined by options
        - executing: an Executing object from the `executing` library, which has:
            - .node: the AST node being executed in this frame, or None if it's unknown
            - .statements: a set of one or more candidate statements (AST nodes, probably just one)
                currently being executed in this frame.
            - .code_qualname(): the __qualname__ of the function or class being executed,
                or just the code name.

    Properties returning one or more pieces of source code (ranges of lines):
        - scope_pieces: all the pieces in the scope
        - included_pieces: a subset of scope_pieces determined by options
        - executing_piece: the piece currently being executed in this frame

    Properties returning lists of Variable objects:
        - variables: all variables in the scope
        - variables_by_lineno: variables organised into lines
        - variables_in_lines: variables contained within FrameInfo.lines
        - variables_in_executing_piece: variables contained within FrameInfo.executing_piece
    Nframe_or_tboptionsc                     t                               |          | _        t          |          \  }| _        || _        |j        | _        |pt                      | _        | j        j	        | _	        d S r   )
rE   r   r   r   framef_coder  r   r  r   )rT   r  r  r   s       r:   r   zFrameInfo.__init__"  s]    
  ))+66-k::t{
L	+'))n+r9   c                 .    d                     |           S )Nz'{self.__class__.__name__}({self.frame})rS   r   rS   s    r:   r   zFrameInfo.__repr__/  s    8??T?JJJr9   T)collapse_repeated_framesr#  rF   c             #       K   t          t          |                    }t          |          r|ddd         } fd}|st          ||          E d{V  dS d }t	          ||t
          |          E d{V  dS )ak  
        An iterator of FrameInfo and RepeatedFrames objects representing
        a full traceback or stack. Similar consecutive frames are collapsed into RepeatedFrames
        objects, so always check what type of object has been yielded.

        Pass either a frame object or a traceback object,
        and optionally an Options object to configure.
        Nrb   c                      |           S r   r8   )fclsr  s    r:   mapperz$FrameInfo.stack_data.<locals>.mapperJ  s    3q'??"r9   c                 8    t          |           \  }}|j        |fS r   )r   r!  )xr   r   s      r:   
_frame_keyz(FrameInfo.stack_data.<locals>._frame_keyQ  s     ,Q//ME6<''r9   )r(  	collapserr   )rQ   r   r!   rn   r   r  )r'  r  r  r#  stackr(  r+  s   ` `    r:   
stack_datazFrameInfo.stack_data2  s        Z,,--
 K   	 $$B$KE	# 	# 	# 	# 	# 	# ( 	65)))))))))F	( 	( 	( %$	
 
 
 	
 	
 	
 	
 	
 	
 	
 	
 	
r9   c                     | j         s| j        j        S | j                            | j                   \  fd| j        j        D             S )a  
        All the pieces (ranges of lines) contained in this object's .scope,
        unless there is no .scope (because the source isn't valid Python syntax)
        in which case it returns all the pieces in the source file, each containing one line.
        c                 @    g | ]}|j         k    |j        k    |S r8   )r%   stop)rK   piece	scope_endscope_starts     r:   rM   z*FrameInfo.scope_pieces.<locals>.<listcomp>g  s<     
 
 
ek))ejI.E.E .E.E.Er9   )r   r   rU   r   )rT   r3  r4  s    @@r:   scope_pieceszFrameInfo.scope_pieces\  sl     z 	&;%%!%!7!7
!C!CY
 
 
 
 
+
 
 
 	
r9   c                    | j         j        }t          j                            |          s*|                    d          r|                    d          r|S dgt          t          j                  z   D ]s}	 t          j        	                    ||          }t          j        
                    |          r!t          j                            |          c S d# t          $ r Y pw xY w|S )z
        A hopefully absolute file path derived from .code.co_filename,
        the current working directory, and sys.path.
        Code based on ipython.
        <>.)r  r  ospathisabs
startswithendswithrQ   sysr   isfileabspath	Exception)rT   r   dirnamefullnames       r:   filenamezFrameInfo.filenamem  s     & f%%	 ))#..	 ,,		 M
 utCH~~- 	 	G7<<887>>(++ 57??8444445    
 s   8AC
C&%C&c                 D     t           fd j        D                       S )z
        The piece (range of lines) containing the line currently being executed
        by the interpreter in this frame.
        c              3   .   K   | ]}j         |v |V  d S r   )r   )rK   r2  rT   s     r:   r   z,FrameInfo.executing_piece.<locals>.<genexpr>  s<       
 
{e## ####
 
r9   )r   r5  rS   s   `r:   executing_piecezFrameInfo.executing_piece  s@      
 
 
 
*
 
 
 
 
 	
r9   c                    | j         }| j         sg S |                    | j                  }t          d|| j        j        z
            }|dz   | j        j        z   }|||         }| j        j        rl| j        j	        
                    d          sMt          | j        t          j        t          j        f          r"|dk    r|                    d|d                    |S )a  
        The list of pieces (ranges of lines) to display for this frame.
        Consists of .executing_piece, surrounding context pieces
        determined by .options.before and .options.after,
        and the function signature if a function is being executed and
        .options.include_signature is True (in which case this might not
        be a contiguous range of pieces).
        Always a subset of .scope_pieces.
        r   r.   r7  )r5  indexrH  r   r  r   r   r   r  r  r=  r~   r   r|   FunctionDefAsyncFunctionDefinsert)rT   r5  pospieces_start
pieces_endrU   s         r:   included_pieceszFrameInfo.included_pieces  s     (  	I  !5661cDL$77881Wt|11
l:56 .	.	)44S99	. tzCOS=Q+RSS	. !1$$MM!\!_---r9   c                    g }d | j         D             }|D ]~}|                                D ]g}t          |j                  t          |j                                                  z
  }t          |j        |          }|                    |           ht          |          dk    rdS t          |dd                   S )z
        The common minimal indentation shared by the markers intended
        for an exception node that spans multiple lines.

        Intended to be used only internally.
        c                 <    g | ]}t          |t                    |S r8   r~   r   rK   lines     r:   rM   z;FrameInfo._executing_node_common_indent.<locals>.<listcomp>  s'    GGG$
40F0FGGGGr9   r.   r   N)	rP   r   rO   r   lstripr   r%   rm   min)rT   indentsrP   rV  r   
begin_textindents          r:   r   z'FrameInfo._executing_node_common_indent  s     GG$*GGG 	' 	'D7799 ' ' ^^c$)2B2B2D2D.E.EE
TZ44v&&&&'
 w<<117122;r9   c                 :     j         }|sg S  j        j        t          j        t          j        fv }d}g }t          |          D ]M\  }}|dk    rP j        rI|d          j        d         k    r2|d          j        d         k    r|	                    t                     n|r|r|j        |j        k    r j        j        t          j        k    r1|	                    t          |j        |j        dz
                       n@t          |j        |j                  D ]%}|	                    t           |                     & fd|D             }| j        k    r"t#          | j        j        t          g          }|                    |           |}Od |D             }	d                    d |	D                       }
t+          |
                                          }t/          |	d         j                  t/          |d                   z
  }|	D ]	}||_        
|S )	a  
        A list of lines to display, determined by options.
        The objects yielded either have type Line, BlankLineRange
        or are the singleton LINE_GAP.
        Always check the type that you're dealing with when iterating.

        LINE_GAP can be created in two ways:
            - by truncating a piece of context that's too long, determined by
                .options.max_lines_per_piece
            - immediately after the signature piece if Options.include_signature is true
              and the following piece isn't already part of the included pieces.

        The Line objects are all within the ranges from .included_pieces.
        Nr.   r   c                 0    g | ]}t          |          S r8   )r   )rK   rL   rT   s     r:   rM   z#FrameInfo.lines.<locals>.<listcomp>  s!    222qT$]]222r9   )
max_lengthmiddlec                 <    g | ]}t          |t                    |S r8   rT  rU  s     r:   rM   z#FrameInfo.lines.<locals>.<listcomp>  s8     
 
 
$%%

 
 
r9   
c              3   $   K   | ]}|j         V  d S r   )r   rU  s     r:   r   z"FrameInfo.lines.<locals>.<genexpr>  s8       
 
 I
 
 
 
 
 
r9   )rQ  r  r   r-   r6   r7   	enumerater   r5  rm   r   r%   r1  r   rJ   r   rH  r   r   extendr   r   
splitlinesrO   r   r   )rT   rU   add_empty_lines
prev_piecer   rL   r2  r   rP   
real_linesr   dedented_linesr   rV  s   `             r:   rP   zFrameInfo.lines  sU     % 	I,2z7I:K\6]]
!&)) 	 	HAuFF
 q	T%6q%999q	T%6q%999h'''' : :EK*/4Q4Q<+z/@@@MM.%+a-"P"PQQQQ"'
"E"E : :d4&8&899992222E222E,,, #|?$:  
 MM%   JJ
 

 
 

 yy 
 
"
 
 
 
 
  0022Z]/003~a7H3I3II 	1 	1D"0Dr9   c                    | j         j        r| j        j        sdS t	          | j        j                  d         }	 |j        }t          |t          j        t          j	        t          j
        t          j        f          r|S F)zY
        The AST node of the innermost function, class or module being executed.
        Nr   )r   rN   r   
statementsrQ   parentr~   r|   rK  rL  ClassDefModule)rT   ry   s     r:   r   zFrameInfo.scope  sw    
 { 	t~'@ 	4DN-..q1	 ;D$#2FVYV` abb 	r9   c                 R   ddl m} | j        j        }| j        }t          |t          d                     t          |           t          ||          rd|_        | j	        
                                }| j        j        }|rYt          |j        dd          rC|                    |          d         }|                    |          \  }}||z  }||z  }||fg}	ng }	|                    |          }
t#          ||
|	          }| j	                            |          d         }||fS )Nr   )HtmlFormatterz(Must set a pygments formatter in OptionsTr  F)pygments.formattersrp  r  r   r   r#   r   r~   nowrapr   r   r   r   r   r  get_text_rangeget_textr"   r   )rT   rp  	formatterr   r   r   r4  r%   r&   r   r  rP   r   s                r:   r   z FrameInfo._pygmented_scope_lines  s<    	655555L3	
	:&PQQRRRi// 	$#I##%%~" 	GIO-A5II 	..u55a8K--d33JE3[ E;Ccl^FFF~~e$$&y$??[++E2215
5  r9   c                      j         sg S t          j         j                  } j         }d |                    |          D             }t          |t          j        t          j        f          rst          j	        |j
                  D ]Y}t          |t          j                  s|j        }	 |j        |         }|                    ||f           J# t          $ r Y Vw xY w fdfdt          |fd          }g }|                                D ]N}	t#          |	 \  }
}|d         } |
d                   }|s*|                    t%          ||
|                     O|S )z
        All Variable objects whose nodes are contained within .scope
        and whose values could be safely evaluated by pure_eval.
        c                 $    g | ]}t          | |S r8   )r   )rK   pairs     r:   rM   z'FrameInfo.variables.<locals>.<listcomp>I  s3     
 
 
($/

 
 
r9   c                     t          | t          j                  r| j        S j                                                            |           S r   )r~   r|   argr   r   rt  )nrT   s    r:   rt  z%FrameInfo.variables.<locals>.get_text\  s@    !SW%% 9u{**,,55a888r9   c                 p    	 t          j        d |           z   dz             S # t          $ r | cY S w xY w)N())r|   parserB  )r{  rt  s    r:   normalise_nodez+FrameInfo.variables.<locals>.normalise_nodeb  sN    yxx{{!2S!8999   s   "& 55c                 J    t          j         | d                             S rX   )r|   dump)nvr  s    r:   rZ   z%FrameInfo.variables.<locals>.<lambda>k  s    sxr!u 5 566 r9   r   )r   r   
from_framer   find_expressionsr~   r|   rK  rL  walkargsrz  namesrm   KeyErrorr   valuesrp   r<   )rT   	evaluatorr   node_valuesr   rA   rC   groupedr   r   rB   r  r   rt  r  s   `            @@r:   	variableszFrameInfo.variables>  s    z 	I(44	

 
!22599
 
 
 ecos/CDEE 
	6,, 	6 	6!$00 x6%OD1E  &&e}5555     D	9 	9 	9 	9 	9	 	 	 	 	 $6666
 

 ^^%% 	8 	8EKME61IE8E!H%%D MM(4667777s   0C
C"!C"c                     t          t                    }| j        D ]M}|j        D ]C}t	          | j                            |           D ]}||                             ||f            DN|S )z
        A mapping from 1-based line numbers to lists of pairs:
            - A Variable object
            - A specific AST node from the variable's .nodes list that's
                in the line at that line number.
        )r   rQ   r  rB   rJ   r   r   rm   )rT   r   varr   r   s        r:   r   zFrameInfo.variables_by_linenoy  s     T""> 	7 	7C	 7 7#T[%;%;D%A%AB 7 7F6N))3+666677 r9   c                 D     t           fd j        D                       S )z[
        A list of Variable objects contained within the lines returned by .lines.
        c              3   v   K   | ]3}t          |t                    j        |j                 D ]	\  }}|V  
4d S r   )r~   r   r   r   )rK   rV  r  r   rT   s       r:   r   z/FrameInfo.variables_in_lines.<locals>.<genexpr>  sp       
 
$%%
 "5dkB	
 
 T 
 
 
 
 
 
 
r9   )r   rP   rS   s   `r:   variables_in_lineszFrameInfo.variables_in_lines  s?    
  
 
 
 


 
 
 
 
 	
r9   c                 D     t           fd j        D                       S )zz
        A list of Variable objects contained within the lines
        in the range returned by .executing_piece.
        c              3   B   K   | ]}j         |         D ]	\  }}|V  
d S r   )r   )rK   r   r  r   rT   s       r:   r   z9FrameInfo.variables_in_executing_piece.<locals>.<genexpr>  sZ       
 
!5f=
 
 T 
 
 
 
 
 
 
r9   )r   rH  rS   s   `r:   variables_in_executing_piecez&FrameInfo.variables_in_executing_piece  s@      
 
 
 
.
 
 
 
 
 	
r9   r   ))r1   r2   r3   r4   r   r   r	   r   r   r   r   classmethodr   r
   r  r.  r    r   rJ   r5  r   rE  rH  rQ  r   r   r   r   r   rP   r|   r   r   r   r   r<   r  r   r   r  r  r8   r9   r:   r   r     s       ! !J *.
, 
,y-78
, g&
, 
, 
, 
,K K K  *.'

 .2'
 '
 '
y-78'
 g&'

 '+'
 
%^34	5'
 '
 '
 ['
R 
d5k 
 
 
 _
  #    _@ 	
 	
 	
 	
 _	
 e    _:  s       _ * =tE$"?@A = = = _=~ x(    _  !sDI~1F(G ! ! ! _!< 84> 8 8 8 _8t WS$uXsw=N7O2P-P%Q    _ 	
DN 	
 	
 	
 _	
 	
d8n 	
 	
 	
 _	
 	
 	
r9   r   )Br|   r   r:  r?  collectionsr   r   enumr   textwrapr   typesr   r   r	   typingr
   r   r   r   r   r   r   r   r   r   r   r   asttokens.utilr   r   	pure_evalr   r   stack_data.utilsr   r   r   r   r   r   r   r    r!   r"   r#   r   r$   r4   r   r   r(   r-   r   r<   rE   r   r=   r   r   r   r   r   r	  r  r   r8   r9   r:   <module>r     s   



  				 



 , , , , , , , ,             4 4 4 4 4 4 4 4 4 4                                                    : : : : : : : :@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
 j"C. #,!3-)* *  z.&,&-$c?,- -            J{(37+,# ! !  "`0 `0 `0 `0 `0Y `0 `0 `0F F  F  F  F  F  F  F  FF    f    799% % % % % % % %q q q q q6 q q qh%[M8E#s(O+DDE 
,   6  &'R 'R 'R 'R 'R 'R 'R 'RT_
 _
 _
 _
 _
 _
 _
 _
 _
 _
r9   