
    yh`E                     P   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	J
r
Jr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  \(       a  SSKJrJr   " S S	\ R:                  S
9r " S S\5      r " S S\5      r Sr!\RD                  SS S:X  a
  \!S-  r!\!S-  r!SS jr#g)    N)Module)IterableIteratorListOptionalTupleAnycastTYPE_CHECKING   )LineNumbers)	Tokenmatch_tokenis_non_coding_tokenpatched_generate_tokens	last_stmtannotate_fstring_nodesgenerate_tokens	is_moduleis_stmt)AstNode	TokenInfoc                   b    \ rS rSrS\S\SS4S jr\R                  S 5       rSS jr	SS	 jr
S
rg)ASTTextBase!   source_textfilenamereturnNc                 R    X l         [        U5      nXl        [        U5      U l        g N)	_filenamestr_textr   _line_numbers)selfr   r   s      kc:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\asttokens/asttokens.py__init__ASTTextBase.__init__"   s%    N
 k"KJ$[1D    c                     [         e)  
Returns two ``(lineno, col_offset)`` tuples for the start and end of the given node.
If the positions can't be determined, or the nodes don't correspond to any particular text,
returns ``(1, 0)`` for both.

``padded`` corresponds to the ``padded`` argument to ``ast.get_source_segment()``.
This means that if ``padded`` is True, the start position will be adjusted to include
leading whitespace if ``node`` is a multiline statement.
)NotImplementedErrorr%   nodepaddeds      r&   get_text_positionsASTTextBase.get_text_positions-   s
     r)   c                     U R                  X5      u  p4U R                  R                  " U6 U R                  R                  " U6 4$ )z
Returns the (startpos, endpos) positions in source text corresponding to the given node.
Returns (0, 0) for nodes (like `Load`) that don't correspond to any particular text.

See ``get_text_positions()`` for details on the ``padded`` argument.
)r0   r$   line_to_offsetr%   r.   r/   startends        r&   get_text_rangeASTTextBase.get_text_range;   sH     ((6JE
''/
''- r)   c                 D    U R                  X5      u  p4U R                  X4 $ )z
Returns the text corresponding to the given node.
Returns '' for nodes (like `Load`) that don't correspond to any particular text.

See ``get_text_positions()`` for details on the ``padded`` argument.
)r7   r#   r4   s        r&   get_textASTTextBase.get_textI   s%     $$T2JE::e!!r)   )r!   r$   r#   )T)__name__
__module____qualname____firstlineno__r"   r'   abcabstractmethodr0   r7   r:   __static_attributes__ r)   r&   r   r   !   s@    	2# 	2 	2 	2  	"r)   r   )	metaclassc                      ^  \ rS rSrSrSU 4S jjrS rS r\S 5       r	\S 5       r
\S 5       r\S	 5       rS
 rS rS rSS jrSS jrSS jr SS jrSS jrS rSrU =r$ )	ASTTokensU   a  
ASTTokens maintains the text of Python code in several forms: as a string, as line numbers, and
as tokens, and is used to mark and access token and position information.

``source_text`` must be a unicode or UTF8-encoded string. If you pass in UTF8 bytes, remember
that all offsets you'll get are to the unicode text, which is available as the ``.text``
property.

If ``parse`` is set, the ``source_text`` will be parsed with ``ast.parse()``, and the resulting
tree marked with token info and made available as the ``.tree`` property.

If ``tree`` is given, it will be marked and made available as the ``.tree`` property. In
addition to the trees produced by the ``ast`` module, ASTTokens will also mark trees produced
using ``astroid`` library <https://www.astroid.org>.

If only ``source_text`` is given, you may use ``.mark_tokens(tree)`` to mark the nodes of an AST
tree created separately.
c                   > [         [        U ]  X5        U(       a  [        R                  " X5      OUU l        Uc  [        U R                  5      n[        U R                  U5      5      U l
        U R                   Vs/ s H  ofR                  PM     snU l        U R
                  (       a  U R                  U R
                  5        g g s  snf r    )superrF   r'   astparse_treer   r#   list_translate_tokens_tokensstartpos_token_offsetsmark_tokens)r%   r   rK   treer   tokenstok	__class__s          r&   r'   ASTTokens.__init__i   s    	)T#K:5:;1DJ ~tzz*f..v67DL 48<<@<C<<<@Dzz
tzz"  As   >C	c                 >    SSK Jn  U" U 5      R                  U5        g)a]  
Given the root of the AST or Astroid tree produced from source_text, visits all nodes marking
them with token and position information by adding ``.first_token`` and
``.last_token`` attributes. This is done automatically in the constructor when ``parse`` or
``tree`` arguments are set, but may be used manually with a separate AST or Astroid tree.
r   )
MarkTokensN)rR   rY   
visit_tree)r%   	root_noderY   s      r&   rR   ASTTokens.mark_tokensz   s     (t	*r)   c              #      #    [        [        U5      5       H\  u  p#Uu  pEpgn[        XEXgXU R                  R	                  US   US   5      U R                  R	                  US   US   5      5      v   M^     g7f)zK
Translates the given standard library tokens into our own representation.
r   r   N)	enumerater   r   r$   r3   )	r%   original_tokensindexrU   tok_typetok_strr5   r6   lines	            r&   rN   ASTTokens._translate_tokens   s|     
   7 HI
,/)hT(U$$33E!HeAhG$$33CFCFCE E Js   A6A8c                     U R                   $ )z,The source code passed into the constructor.)r#   r%   s    r&   textASTTokens.text        ::r)   c                     U R                   $ )zIThe list of tokens corresponding to the source code from the constructor.)rO   rf   s    r&   rT   ASTTokens.tokens   s     <<r)   c                     U R                   $ )zTThe root of the AST tree passed into the constructor or parsed from the source code.)rL   rf   s    r&   rS   ASTTokens.tree   ri   r)   c                     U R                   $ )zThe filename that was parsed)r!   rf   s    r&   r   ASTTokens.filename   s     >>r)   c                 d    U R                   [        R                  " U R                  U5      S-
     $ )z
Returns the token containing the given character offset (0-based position in source text),
or the preceeding token if the position is between tokens.
r   )rO   bisectrQ   )r%   offsets     r&   get_token_from_offsetASTTokens.get_token_from_offset   s)     <<d&9&96BQFGGr)   c                 V    U R                  U R                  R                  X5      5      $ )z
Returns the token containing the given (lineno, col_offset) position, or the preceeding token
if the position is between tokens.
)rs   r$   r3   r%   lineno
col_offsets      r&   	get_tokenASTTokens.get_token   s&     %%d&8&8&G&G&[\\r)   c                 V    U R                  XR                  R                  X5      5      $ )z\
Same as get_token(), but interprets col_offset as a UTF8 offset, which is what `ast` uses.
)ry   r$   from_utf8_colrv   s      r&   get_token_from_utf8ASTTokens.get_token_from_utf8   s$    
 >>&"4"4"B"B6"VWWr)   c                     UR                   S-   nU(       dU  [        U R                  U   R                  5      (       a.  US-  n[        U R                  U   R                  5      (       a  M.  U R                  U   $ )z
Returns the next token after the given one. If include_extra is True, includes non-coding
tokens from the tokenize module, such as NL and COMMENT.
r   r`   r   rO   typer%   rU   include_extrais       r&   
next_tokenASTTokens.next_token   _     			AAQ 4 455	Q  Q 4 455<<?r)   c                     UR                   S-
  nU(       dU  [        U R                  U   R                  5      (       a.  US-  n[        U R                  U   R                  5      (       a  M.  U R                  U   $ )z
Returns the previous token before the given one. If include_extra is True, includes non-coding
tokens from the tokenize module, such as NL and COMMENT.
r   r   r   s       r&   
prev_tokenASTTokens.prev_token   r   r)   c                 2   UnU(       a  U R                   OU R                  n[        XRU5      (       dd  [        R                  " UR
                  5      (       d?  U" USS9n[        XRU5      (       d'  [        R                  " UR
                  5      (       d  M?  U$ )z
Looks for the first token, starting at start_token, that matches tok_type and, if given, the
token string. Searches backwards if reverse is True. Returns ENDMARKER token if not found (you
can check it with `token.ISEOF(t.type)`).
Tr   )r   r   r   tokenISEOFr   )r%   start_tokenra   rb   reversetadvances          r&   
find_tokenASTTokens.find_token   sk     	A!(doodooG!w//AFF8K8K
!4
(a !w//AFF8K8KHr)   c              #      #    [        UR                  UR                  S-   5       HD  nU(       d)  [        U R                  U   R                  5      (       a  M3  U R                  U   v   MF     g7f)z
Yields all tokens in order from first_token through and including last_token. If
include_extra is True, includes non-coding tokens such as tokenize.NL and .COMMENT.
r   N)ranger`   r   rO   r   )r%   first_token
last_tokenr   r   s        r&   token_rangeASTTokens.token_range   sS      ;$$j&6&6&:;	1$,,q/2F2FGGll1o <s   AA/A/c                 L    U R                  UR                  UR                  US9$ )z
Yields all tokens making up the given node. If include_extra is True, includes non-coding
tokens such as tokenize.NL and .COMMENT.
r   )r   r   r   )r%   r.   r   s      r&   
get_tokensASTTokens.get_tokens   s&     D,,doo][[r)   c                     [        US5      (       d  gUR                  R                  nUR                  R                  nU(       a-  [        S U R                  U5       5       5      (       a  US   S4nX44$ )r+   r   r   r   r   c              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7fr    )r   r   NEWLINE).0r   s     r&   	<genexpr>/ASTTokens.get_text_positions.<locals>.<genexpr>  s      S=Rk!U]]33=Rs   ')r   )hasattrr   r5   r   r6   anyr   r4   s        r&   r0   ASTTokens.get_text_positions   se     4''""E
//

C#ST__T=RSSSQxme:r)   )rQ   rO   rL   )FN	<unknown>N)F)NF)r<   r=   r>   r?   __doc__r'   rR   rN   propertyrg   rT   rS   r   rs   ry   r}   r   r   r   r   r   r0   rB   __classcell__rV   s   @r&   rF   rF   U   s    &#"
+	E  
  
  
  
H	]X

  !&\ r)   rF   c                   \   ^  \ rS rSrSrS	U 4S jjr\S 5       r\S 5       rS r	S r
SrU =r$ )
ASTTexti  a4  
Supports the same ``get_text*`` methods as ``ASTTokens``,
but uses the AST to determine the text positions instead of tokens.
This is faster than ``ASTTokens`` as it requires less setup work.

It also (sometimes) supports nodes inside f-strings, which ``ASTTokens`` doesn't.

Some node types and/or Python versions are not supported.
In these cases the ``get_text*`` methods will fall back to using ``ASTTokens``
which incurs the usual setup cost the first time.
If you want to avoid this, check ``supports_tokenless(node)`` before calling ``get_text*`` methods.
c                    > [         [        U ]  X5        X l        U R                  b  [	        U R                  5        S U l        g r    )rI   r   r'   rL   r   
_asttokens)r%   r   rS   r   rV   s       r&   r'   ASTText.__init__"  s4    	'4!+8JzzTZZ(DOr)   c                     U R                   cE  [        R                  " U R                  U R                  5      U l         [        U R                   5        U R                   $ r    )rL   rJ   rK   r#   r!   r   rf   s    r&   rS   ASTText.tree,  s>     zz99TZZ8djTZZ(::r)   c                     U R                   c.  [        U R                  U R                  U R                  S9U l         U R                   $ )N)rS   r   )r   rF   r#   rS   r!   rf   s    r&   	asttokensASTText.asttokens4  s;     !
**yy>>do
 ??r)   c                    [        U5      (       a0  SU R                  R                  [        U R                  5      5      4$ [        USS5      c  gU(       d   e[        US/ 5      nU(       d  [        USS5      n[        US/ 5      nU(       a  US   nOUnUR                  n[        U5      nU(       aC  XgR                  :w  d1  XaR                  :w  a%  [        US	S5      (       a  [        U5      (       a  SnO%U R                  R                  XeR                  5      nXh4n	[        [        UR                  5      n
[        [        UR                  5      nU R                  R                  X5      nX4nX4$ )
z>
Version of ``get_text_positions()`` that doesn't use tokens.
r   rw   Nr   decorator_list
decoratorsnodesr   doc_node)r   r$   offset_to_linelenr#   getattrrw   r   
end_linenor   r|   rx   r
   intend_col_offset)r%   r.   r/   r   decorators_node
start_nodestart_linenoend_nodestart_col_offsetr5   r   r   r6   s                r&   _get_text_positions_tokenless%ASTText._get_text_positions_tokenless?  sM   
 
 T''66s4::GGGtXt$,K4/4JlD9o?GR8j a=jj$$LH ' OO+j$// ++99,H]H]^,E
 c8../J#x667N''55jQN
&C:r)   c                     [        USS5      (       a  g[        U5      (       a  U R                  X5      $ U R                  R	                  X5      $ )r+   _broken_positionsNr   )r   supports_tokenlessr   r   r0   r-   s      r&   r0   ASTText.get_text_positions  sH     t($//$//==>>,,T::r)   )r   rL   )Nr   )r<   r=   r>   r?   r   r'   r   rS   r   r   r0   rB   r   r   s   @r&   r   r     sF        @D; ;r)   r   )	arguments	Argumentswithitem   )      )argStarred)SliceExtSliceIndexkeywordc                    [        U 5      R                  [        ;  =(       a    [        U [        R
                  5      (       + =(       aL    U SL=(       aA    [        U 5      R                  S:H  =(       a"    [        U R                  5      R                  S;   (       + =(       a!    S[        R                  R                  5       ;  $ )aT  
Returns True if the Python version and the node (if given) are supported by
the ``get_text*`` methods of ``ASTText`` without falling back to ``ASTTokens``.
See ``ASTText`` for why this matters.

The following cases are not supported:

  - PyPy
  - ``ast.arguments`` / ``astroid.Arguments``
  - ``ast.withitem``
  - ``astroid.Comprehension``
  - ``astroid.AssignName`` inside ``astroid.Arguments`` or ``astroid.ExceptHandler``
  - The following nodes in Python 3.8 only:
    - ``ast.arg``
    - ``ast.Starred``
    - ``ast.Slice``
    - ``ast.ExtSlice``
    - ``ast.Index``
    - ``ast.keyword``
N
AssignName)r   ExceptHandlerpypy)
r   r<   _unsupported_tokenless_types
isinstancerJ   ASTparentsysversionlower)r.   s    r&   r   r     s    . 4j!== 
, tSWW%% 	
$d*: 	
J</ MT[[!**.LL
, ))+
+r)   r    )$r@   rJ   rq   r   r   r   typingr   r   r   r   r   r	   r
   r   line_numbersr   utilr   r   r   r   r   r   r   r   r   r   r   ABCMetar   rF   r   r   version_infor   rC   r)   r&   <module>r      s     
  
   V V V %  
 &1"CKK 1"h} }@~;k ~;F  F BQ6!"44"KK"r)   