
    c*b.'                        d dl Z d dlZd dlZd dlmZ d Z G d d ej                  dd            ZddZddZ	 e
ed	      rd
 Znd Zd Zd Z ee j                        D  ch c]Q  \  } } e|e      s e|e j$                  e j&                  e j(                  e j*                  e j,                  f      r|S c}} Zd Z ee j                        D  ch c]#  \  } } e|e      r e|e j2                        r| % c}} Z ee j                        D  ch c]#  \  } } e|e      r e|e j6                        r| % c}} h dz  Zd Zd Zd Zd Z d Z!d Z" e#       Z$d Z%d Z&d Z' G d de#      Z(yc c}} w c c}} w c c}} w )    N)	iteritemsc                 b    t         j                  |    dt        |      j                  d      S )zRReturns a human-friendly representation of a token with the given type and string.:u)tokentok_namereprlstrip)tok_typestrings     .lib/python3.12/site-packages/asttokens/util.py
token_reprr      s'     NN8,d6l.A.A#.F	GG    c                       e Zd ZdZd Zy)Tokena  
  TokenInfo is an 8-tuple containing the same 5 fields as the tokens produced by the tokenize
  module, and 3 additional ones useful for this module:

  - [0] .type     Token type (see token.py)
  - [1] .string   Token (a string)
  - [2] .start    Starting (row, column) indices of the token (a 2-tuple of ints)
  - [3] .end      Ending (row, column) indices of the token (a 2-tuple of ints)
  - [4] .line     Original line (string)
  - [5] .index    Index of the token in the list of tokens that it belongs to.
  - [6] .startpos Starting character offset into the input text.
  - [7] .endpos   Ending character offset into the input text.
  c                 B    t        | j                  | j                        S N)r   typer   selfs    r   __str__zToken.__str__)   s    dii--r   N)__name__
__module____qualname____doc__r    r   r   r   r      s    .r   r   z0type string start end line index startpos endposc                 N    | j                   |k(  xr |du xs | j                  |k(  S )zVReturns true if token is of the given type and, if a string is given, has that string.N)r   r   r   r   tok_strs      r   match_tokenr    -   s(    	x		PW_%O8OPr   c                     t        | ||      sGt        dt        ||      dt        |       d| j                  d   d| j                  d   dz         y)z
  Verifies that the given token is of the expected type. If tok_str is given, the token string
  is verified too. If the token doesn't match, raises an informative ValueError.
  zExpected token z, got z	 on line r   z col    N)r    
ValueErrorr   strstartr   s      r   expect_tokenr&   2   sQ    
 
UHg	.
7#SZkk!nekk!nq(* + + 
/r   ENCODINGc                 d    | t         j                  t         j                  t         j                  fv S zW
    These are considered non-coding tokens, as they don't affect the syntax tree.
    )r   NLCOMMENTr'   
token_types    r   is_non_coding_tokenr.   ?   s"     %((EMM5>>BBBr   c                 (    | t         j                  k\  S r)   )r   N_TOKENSr,   s    r   r.   r.   E   s     ''r   c                 2    t        | d      rt        S t        S )z
  Returns a function which yields all direct children of a AST node,
  skipping children that are singleton nodes.
  The function depends on whether ``node`` is from ``ast`` or from the ``astroid`` module.
  get_children)hasattriter_children_astroiditer_children_astnodes    r   iter_children_funcr8   L   s     #*$"?	VEVVr   c                 <    t        |       rg S | j                         S r   )is_joined_strr2   r6   s    r   r4   r4   U   s    4I				r   c              #      K   t        |       ry t        | t        j                        r3t	        | j
                  | j                        D ]  \  }}|| |  y t        j                  |       D ]  }|j                  t        vs|  y wr   )
r:   
isinstanceastDictzipkeysvaluesiter_child_nodes	__class__
SINGLETONS)r7   keyvaluechilds       r   r5   r5   `   sz     4
chh DIIt{{3e		k 4 ##D)e j(k *s   BBB>   ConstDelAttrDelName
AssignAttr
AssignNamec                 :    | j                   j                  t        v S )z+Returns whether node is an expression node.)rC   r   expr_class_namesr6   s    r   is_exprrO   ~       		 	 $4	44r   c                 :    | j                   j                  t        v S )z)Returns whether node is a statement node.)rC   r   stmt_class_namesr6   s    r   is_stmtrS      rP   r   c                 4    | j                   j                  dk(  S )z&Returns whether node is a module node.ModulerC   r   r6   s    r   	is_modulerW      s    		 	 H	,,r   c                 4    | j                   j                  dk(  S )zFReturns whether node is a JoinedStr node, used to represent f-strings.	JoinedStrrV   r6   s    r   r:   r:      s     
	 	 K	//r   c                 4    | j                   j                  dk(  S )z2Returns whether node is a starred expression node.StarredrV   r6   s    r   
is_starredr\      s    		 	 I	--r   c                     | j                   j                  dv xs> | j                   j                  dk(  xr# t        t        t        | j
                              S )z?Returns whether node represents a slice, e.g. `1:2` in `x[1:2]`)SliceExtSliceTuple)rC   r   anymapis_sliceeltsr6   s    r   rc   rc      sK    
 nn!66 
..
!
!W
, ,#h		*+	r   c                 z   |sd }t        |       }t               }d}| dt        fg}|r|j                         \  }}}	|	t        u ri||vsJ |j	                  |        |||      \  }
}|j                  |||f       t        |      } ||      D ]  }|j                  |||
t        f        n
 ||||	      }|r|S )a5  
  Scans the tree under the node depth-first using an explicit stack. It avoids implicit recursion
  via the function call stack to avoid hitting 'maximum recursion depth exceeded' error.

  It calls ``previsit()`` and ``postvisit()`` as follows:

  * ``previsit(node, par_value)`` - should return ``(par_value, value)``
        ``par_value`` is as returned from ``previsit()`` of the parent.

  * ``postvisit(node, par_value, value)`` - should return ``value``
        ``par_value`` is as returned from ``previsit()`` of the parent, and ``value`` is as
        returned from ``previsit()`` of this node itself. The return ``value`` is ignored except
        the one for the root node, which is returned from the overall ``visit_tree()`` call.

  For the initial node, ``par_value`` is None. ``postvisit`` may be None.
  c                      y r   r   )r7   pvaluerF   s      r   <lambda>zvisit_tree.<locals>.<lambda>   s    Dr   N)r8   set	_PREVISITpopaddappendleninsert)r7   previsit	postvisititer_childrendoneretstackcurrent	par_valuerF   rg   
post_valueinsns                 r   
visit_treer{      s    " 
0I$T*-	$#$	"
#% %		GY	D   
hhw#GY7fjllGY
34 JcW%!S1fi01 & gy%0c 	 
*r   c              #      K   t        |       }t               }| g}|rY|j                         }||vsJ |j                  |       | t	        |      } ||      D ]  }|j                  ||        |rXyyw)a  
  Recursively yield all descendant nodes in the tree starting at ``node`` (including ``node``
  itself), using depth-first pre-order traversal (yieling parents before their children).

  This is similar to ``ast.walk()``, but with a different order, and it works for both ``ast`` and
  ``astroid`` trees. Also, as ``iter_children()``, it skips singleton nodes generated by ``ast``.
  N)r8   ri   rk   rl   rn   ro   )r7   rr   rs   ru   rv   ry   cs          r   walkr~      sz      %T*-	$&%iikG$HHW
M e*C7#ll3 $ 	s   A2A75A7c                     d}g }t        |      D ]-  \  }}}|j                  | ||        |j                  |       |}/ |j                  | |d        dj                  |      S )ah  
  Replaces multiple slices of text with new values. This is a convenience method for making code
  modifications of ranges e.g. as identified by ``ASTTokens.get_text_range(node)``. Replacements is
  an iterable of ``(start, end, new_text)`` tuples.

  For example, ``replace("this is a test", [(0, 4, "X"), (8, 9, "THE")])`` produces
  ``"X is THE test"``.
  r   N )sortedrm   join)textreplacementsppartsr%   endnew_texts          r   replacer      si     !
% &| 4uc8	LLa	LLA !5 ,,tABx	r   c                       e Zd ZdZd Zd Zy)NodeMethodsz[
  Helper to get `visit_{node_type}` methods given a node's class and cache the results.
  c                     i | _         y r   )_cacher   s    r   __init__zNodeMethods.__init__  s	    DKr   c                     | j                   j                  |      }|sCd|j                  j                         z   }t	        |||j
                        }|| j                   |<   |S )z
    Using the lowercase name of the class as node_type, returns `obj.visit_{node_type}`,
    or `obj.visit_default` if the type-specific method is not found.
    visit_)r   getr   lowergetattrvisit_default)r   objclsmethodnames        r   r   zNodeMethods.get  sW    
 [[__S!F**,,dsD#"3"34fdkk#Mr   N)r   r   r   r   r   r   r   r   r   r   r      s    
r   r   r   ))r=   collectionsr   sixr   r   
namedtupler   r    r&   r3   r.   r8   r4   __dict__r<   r   
issubclassexpr_contextboolopoperatorunaryopcmpoprD   r5   stmtrR   exprrN   rO   rS   rW   r:   r\   rc   objectrj   r{   r~   r   r   )rz   r}   s   00r   <module>r      s      H."K""7,^_ .$Q
+ 5*C(W &cll3 c3DAqz!T7JS--szz3<<VYV_V_`a 3 c
, #,CLL"9 H"9$!Q!!T*z!SXX/F "9 H #,S\\#: H#:41a!!T*z!SXX/F #: HOP 55-0.

 H	'V2&& Ac2HHs   %E77AE7(E=(F