
    hC                     
   % S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SK JrJ	r	J
r
  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJrJr  \(       a$  SSKJr   " S S	\
5      r\\\4   r\R<                  rS
 r " S S\R@                  " SS5      5      r!S.S jr"S.S jr#S r$S r%S r&S/S jr'\ RP                  RS                  5        V Vs1 s H^  u  p\*" U\+5      (       d  M  \," U\ RZ                  \ R\                  \ R^                  \ R`                  \ Rb                  45      (       d  M\  UiM`     snn r2S/S jr3\ RP                  RS                  5        V Vs1 s H1  u  p\*" U\+5      (       d  M  \," U\ Rh                  5      (       d  M/  U iM3     snn r5\ RP                  RS                  5        V Vs1 s H1  u  p\*" U\+5      (       d  M  \," U\ R                  5      (       d  M/  U iM3     snn 1 Sk-  r6S r7S r8S r9S r:S r;\ Rx                  4r=\\S4   \>S'    S SK?J@r@  \=\@4-  r=S rBS rCS  rDS! rES" rF\G" 5       rHS# rIS/S$ jrJS% rK " S& S'5      rLS( rMS) rNS* rO\" SS+9S, 5       rPS- rQgs  snn f s  snn f s  snn f ! \A a     N^f = f)0    N)ABCMeta)ModuleexprAST)	lru_cache)CallableDictIterableIteratorListOptionalTupleUnioncastAnyTYPE_CHECKINGType   )NodeNGc                        \ rS rSrSrSrSrSrg)EnhancedAST,   Nr    )__name__
__module____qualname____firstlineno__first_token
last_tokenlineno__static_attributes__r       aC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\asttokens/util.pyr   r   ,   s    KJFr"   r   c                 f    [         R                  U    < S[        U5      R                  S5      < 3$ )zRReturns a human-friendly representation of a token with the given type and string.:u)tokentok_namereprlstrip)tok_typestrings     r#   
token_reprr-   7   s'     NN8,d6l.A.A#.F	GGr"   c                       \ rS rSrSrS rSrg)Token>   am  
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    [        U R                  U R                  5      $ N)r-   typer,   selfs    r#   __str__Token.__str__L   s    dii--r"   r   N)r   r   r   r   __doc__r6   r!   r   r"   r#   r/   r/   >   s    .r"   r/   z0type string start end line index startpos endposc                 b    U R                   U:H  =(       a    USL =(       d    U R                  U:H  $ )zVReturns true if token is of the given type and, if a string is given, has that string.N)r3   r,   r'   r+   tok_strs      r#   match_tokenr<   Q   s*     
x		PW_%O8OPr"   c                     [        XU5      (       dJ  [        S[        X5      < S[        U 5      < SU R                  S   < SU R                  S   S-   < 35      eg)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 r   N)r<   
ValueErrorr-   strstartr:   s      r#   expect_tokenrA   W   sP     
Ug	.	.
#SZkk!nekk!nq(* + + 
/r"   c                 f    U [         R                  [         R                  [         R                  4;   $ )zO
These are considered non-coding tokens, as they don't affect the syntax tree.
)r'   NLCOMMENTENCODING)
token_types    r#   is_non_coding_tokenrG   c   s"    
 
%--@	@@r"   c                     [         R                  " [        [        / [        4   [
        R                  " U 5      R                  5      5      $ )z7
Generates standard library tokens for the given code.
)tokenizegenerate_tokensr   r   r?   ioStringIOreadline)texts    r#   rJ   rJ   k   s4     
	!	!$xC'8"++d:K:T:T"U	VVr"   c                 <    [        U S5      (       a  [        $ [        $ )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_funcrV   v   s     #*$"?"?	VEVVr"   c                 T    U(       d  [        U 5      (       a  / $ U R                  5       $ r2   )is_joined_strrP   )rU   include_joined_strs     r#   rR   rR      s#    	d 3 3I				r"   c              #   R  #    U(       d  [        U 5      (       a  g [        U [        R                  5      (       a5  [	        U R
                  U R                  5       H  u  p#Ub  Uv   Uv   M     g [        R                  " U 5       H  nUR                  [        ;  d  M  Uv   M     g 7fr2   )
rX   
isinstanceastr	   zipkeysvaluesiter_child_nodes	__class__
SINGLETONS)rU   rY   keyvaluechilds        r#   rS   rS      s     	d 3 3
chh DIIt{{3		k 4 ##D)e j(k *s   BB'	B'>   ConstDelAttrDelName
AssignAttr
AssignNamec                 <    U R                   R                  [        ;   $ )z+Returns whether node is an expression node.)ra   r   expr_class_namesrT   s    r#   is_exprrm           
	 	 $4	44r"   c                 <    U R                   R                  [        ;   $ )z)Returns whether node is a statement node.)ra   r   stmt_class_namesrT   s    r#   is_stmtrq      rn   r"   c                 4    U R                   R                  S:H  $ )z&Returns whether node is a module node.r   ra   r   rT   s    r#   	is_modulert      s     
	 	 H	,,r"   c                 4    U R                   R                  S:H  $ )zFReturns whether node is a JoinedStr node, used to represent f-strings.	JoinedStrrs   rT   s    r#   rX   rX      s    
 
	 	 K	//r"   c                 4    U R                   R                  S:H  $ )zSReturns whether node is an `Expr` node, which is a statement that is an expression.Exprrs   rT   s    r#   is_expr_stmtry      s     
	 	 F	**r"   .CONSTANT_CLASSES)rf   c                 "    [        U [        5      $ )z(Returns whether node is a Constant node.)r[   rz   rT   s    r#   is_constantr|      s     
D*	++r"   c                 J    [        U 5      =(       a    U R                  [        L $ )z)Returns whether node is an Ellipsis node.)r|   rd   EllipsisrT   s    r#   is_ellipsisr      s     
T		5tzzX55r"   c                 4    U R                   R                  S:H  $ )z2Returns whether node is a starred expression node.Starredrs   rT   s    r#   
is_starredr      s     
	 	 I	--r"   c           	          U R                   R                  S;   =(       d[    U R                   R                  S:H  =(       a;    [        [        [        [        [        R                  U 5      R                  5      5      $ )z?Returns whether node represents a slice, e.g. `1:2` in `x[1:2]`)SliceExtSlicer   )	ra   r   anymapis_slicer   r\   r   eltsrT   s    r#   r   r      sX     nn!66 
..
!
!W
, =#hSYY 5 : :;<	r"   c                    U R                   R                  S:H  =(       ac    [        U [        R                  5      (       + =(       a=    U R
                  U R                  s=L =(       a    U R                  s=L =(       a    S L $ s  $ )Nr   )ra   r   r[   r\   r   loweruppersteprT   s    r#   is_empty_astroid_slicer      sd     nn( 8sww'
'8
**


7
7dii
7
74
7 8r"   c                    U(       d  S n[        U 5      n[        5       nSnU S[        4/nU(       a  UR                  5       u  pxn	U	[        L ah  Xt;  d   eUR	                  U5        U" Xx5      u  pUR                  XxU45        [        U5      nU" U5       H  nUR                  XU
[        45        M     OU" Xx[        [        [           U	5      5      nU(       a  M  U$ )a  
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                     g r2   r   )rU   pvaluerd   s      r#   <lambda>visit_tree.<locals>.<lambda>  s    Dr"   N)rV   set	_PREVISITpopaddappendleninsertr   r   r/   )rU   previsit	postvisititer_childrendoneretstackcurrent	par_valuerd   r   
post_valueinsns                 r#   
visit_treer      s    $ 
0I$T*-	$#$	"
#% %		G	   
hhw#G7fllG
34 JcW%!Sfi01 & g$x*FGc 	 
*r"   c              #     #    [        U 5      n[        5       nU /nU(       aa  UR                  5       nXS;  d   eUR                  U5        Uv   [	        U5      nU" XQ5       H  nUR                  Xg5        M     U(       a  M`  gg7f)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``.

By default, ``JoinedStr`` (f-string) nodes and their contents are skipped
because they previously couldn't be handled. Set ``include_joined_str`` to True to include them.
N)rV   r   r   r   r   r   )rU   rY   r   r   r   r   r   cs           r#   walkr   '  sw      %T*-	$&%iikGHHW
M e*C77ll3 8 	s   A>BBc                     Sn/ n[        U5       H,  u  pEnUR                  XU 5        UR                  U5        UnM.     UR                  XS 5        SR                  U5      $ )a\  
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 )sortedr   join)rN   replacementsppartsr@   endnew_texts          r#   replacer   D  sc     !
% &| 4u8	LL	LLA !5 ,,tBx	r"   c                   $    \ rS rSrSrS rS rSrg)NodeMethodsiX  zW
Helper to get `visit_{node_type}` methods given a node's class and cache the results.
c                     0 U l         g r2   _cacher4   s    r#   __init__NodeMethods.__init__\  s	    DKr"   c                     U R                   R                  U5      nU(       dA  SUR                  R                  5       -   n[	        XUR
                  5      nX0R                   U'   U$ )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   r   getattrvisit_default)r5   objclsmethodnames        r#   r   NodeMethods.get`  sS     [[__S!F**,,ds#"3"34fkk#Mr"   r   N)r   r   r   r   r8   r   r   r!   r   r"   r#   r   r   X  s    r"   r   c              #   n  #    / nU  H  nUR                   [        R                  [        R                  [        R                  4;   a7  U(       a  US   R
                  UR                  :X  a  UR                  U5        Mw  [        U5       H  nUv   M	     / nUv   M     [        U5       H  nUv   M	     g7f)a  
Fixes tokens yielded by `tokenize.generate_tokens` to handle more non-ASCII characters in identifiers.
Workaround for https://github.com/python/cpython/issues/68382.
Should only be used when tokenizing a string that is known to be valid syntax,
because it assumes that error tokens are not actually errors.
Combines groups of consecutive NAME, NUMBER, and/or ERRORTOKEN tokens into a single NAME token.
N)	r3   rI   NAME
ERRORTOKENNUMBERr   r@   r   combine_tokens)original_tokensgrouptokcombined_tokens       r#   patched_generate_tokensr   n  s      E
((x}}h&9&98??K
KE"IMMSYY6S,U3N
 4	  )/ 0s   B3B5c                 X   [        S U  5       5      (       a)  [        U  Vs1 s H  oR                  iM     sn5      S:w  a  U $ [        R                  " [        R
                  SR                  S U  5       5      U S   R                  U S   R                  U S   R                  S9/$ s  snf )Nc              3   Z   #    U  H!  oR                   [        R                  :H  v   M#     g 7fr2   )r3   rI   r   ).0r   s     r#   	<genexpr>!combine_tokens.<locals>.<genexpr>  s     @%3xx8...%s   )+r   r   c              3   8   #    U  H  oR                   v   M     g 7fr2   )r,   )r   ts     r#   r   r     s     /Axxs   r   r   )r3   r,   r@   r   line)	r   r   r   rI   	TokenInfor   r   r@   r   )r   r   s     r#   r   r     s    @%@@@C]bHc]bVY]bHcDdhiDil]]ww///Ahnn"IMM1X]]  Ids   B'c                     [        U 5      " U 5       Vs/ s H0  n[        U5      (       d  [        U5      R                  S;   d  M.  UPM2     nnU(       a  [	        US   5      $ U $ s  snf )zk
If the given AST node contains multiple statements, return the last one.
Otherwise, just return the node.
)excepthandlerExceptHandler
match_case	MatchCase	TryExcept
TryFinallyr   )rV   rq   r3   r   	last_stmt)rU   re   child_stmtss      r#   r   r     sk     *$/5
5eu~~e-- 2  
5  
 [_%%	+
s   -A$A$)maxsizec                    ^ Sm[         R                  " T5      n [         R                  " U 5       Vs/ s H&  n[        U[         R                  5      (       d  M$  UPM(     nnU Vs/ s H  oR
                  UR                  4PM     nn[        [        U5      5      [        U5      :H  n[        U4S jU 5       5      nU=(       a    U$ s  snf s  snf )a  
The positions attached to nodes inside f-string FormattedValues have some bugs
that were fixed in Python 3.9.7 in https://github.com/python/cpython/pull/27729.
This checks for those bugs more concretely without relying on the Python version.
Specifically this checks:
 - Values with a format spec or conversion
 - Repeated (i.e. identical-looking) expressions
 - f-strings implicitly concatenated over multiple lines.
 - Multiline, triple-quoted f-strings.
z(
    f"a {b}{b} c {d!r} e {f:g} h {i:{j}} k {l:{m:n}}"
    f"a {b}{b} c {d!r} e {f:g} h {i:{j}} k {l:{m:n}}"
    f"{x + y + z} {x} {y} {z} {z} {z!a} {z:z}"
    f'''
    {s} {t}
    {u} {v}
    '''
  )c              3   l   >#    U  H)  n[         R                  " TU5      UR                  :H  v   M+     g 7fr2   )r\   get_source_segmentid)r   rU   sources     r#   r   )fstring_positions_work.<locals>.<genexpr>  s.        64(DGG3s   14)
r\   parser   r[   Namer    
col_offsetr   r   all)treerU   
name_nodesname_positionspositions_are_uniquecorrect_source_segmentsr   s         @r#   fstring_positions_workr     s    & 
6	$!$$N:dCHH3M*N?IJzt[[$//2z.JS01S5HH     
	9"99 OJs   #CC%!Cc                    [         R                  S:  a  g[        U SS9 H  n[        U[        R
                  5      (       d  M$  UR                   H  n[        USS5        [        U[        R                  5      (       d  M1  [        5       (       d)  [        UR                  5       H  n[        USS5        M     UR                  (       d  M|  [        UR                  SS5        M     M     g)zs
Add a special attribute `_broken_positions` to nodes inside f-strings
if the lineno/col_offset cannot be trusted.
)      NT)rY   _broken_positions)sysversion_infor   r[   r\   rv   r_   setattrFormattedValuer   rd   format_spec)r   	joinedstrpartre   s       r#   annotate_fstring_nodesr     s     	  6ii//  d'.	D#,,	-	-%''DJJ'eE.5 ( 
$""$7
> ! 7r"   r2   )F)Rr\   collectionsrK   r   r'   rI   abcr   r   r   r   	functoolsr   typingr   r	   r
   r   r   r   r   r   r   r   r   r   astroid_compatr   r   AstNoder   r-   
namedtupler/   r<   rA   rG   rJ   rV   rR   __dict__itemsr[   r3   
issubclassexpr_contextboolopoperatorunaryopcmpoprb   rS   stmtrp   rl   rm   rq   rt   rX   ry   Constantrz   __annotations__astroidrf   ImportErrorr|   r   r   r   r   objectr   r   r   r   r   r   r   r   r   r   )r   r   s   00r#   <module>r     s     	 
    ! !     $C  +v%&'  )H.K""7,^_ .&Q	+AWW  LL..0 c0DAJq$4GaS--szz3<<VYV_V_`a 0 c
, #&,,"4"4"6 H"6$!!!T* /9!SXX/F "6 H #&<<#5#5#7 H#741!!T* /9!SXX/F #7 HOP 5
5
-
0+ '*ll_ %c	" 4uh
,6. H	(V:( ,2. 4: :>?K
c4HHP  sI   I'#AI'*I'I-.I-I-/I3I3!I3I9 9JJ