
    ;ef;                        	 d dl mZ d dlmZmZ d dlmZ d dlm	Z	 d Z
d Zd Zd Zd,d
Zd Zd Zd Z e             e            fdZd-dZd Zd Zd,dZd Zd,dZd,dZd Zd Zd Zd Zd Zh dZd Z da!da"da#d a$d! Z%d" Z&d# Z'd$ Z(d% Z)d& Z*d' Z+d( Z,ej-        ej.        hZ/d,d)Z0ej.        ej-        ej1        hZ2d* Z3d,d+Z4d	S ).   )token)LeafNode)python_symbols)patcompc                 l    t          t          j        | t          t          j        d          |g          S )N=)r   symsargumentr   r   EQUAL)keywordvalues     )/usr/lib/python3.11/lib2to3/fixer_util.py
KeywordArgr      s.    $u{C00%8: : :    c                  6    t          t          j        d          S )N()r   r   LPAR r   r   LParenr          
C   r   c                  6    t          t          j        d          S )N))r   r   RPARr   r   r   RParenr      r   r   c           	          	 t          | t                    s| g} t          |t                    s
d|_        |g}t          t          j        | t          t          j        dd          gz   |z             S )N r	   prefix)	
isinstancelistr   r   r
   atomr   r   r   )targetsources     r   Assignr%      sx    'fd## fd## 	$u{C<<<==FH H Hr   Nc                 <    	 t          t          j        | |          S Nr   )r   r   NAME)namer   s     r   Namer*   $   s    
D0000r   c                 X    	 | t          t          j        t                      |g          gS N)r   r
   trailerDot)objattrs     r   Attrr1   (   s$    #dlSUUDM2233r   c                  8    	 t          t          j        d          S )N,)r   r   COMMAr   r   r   Commar5   ,   s    S!!!r   c                  8    	 t          t          j        d          S )N.)r   r   DOTr   r   r   r.   r.   0   s    	3r   c                     	 t          t          j        |                                |                                g          }| r.|                    dt          t          j        |                      |S )Nr   )r   r
   r-   cloneinsert_childarglist)argslparenrparennodes       r   ArgListrA   4   sZ    7v||~~v||~~>??D 7!T$,55666Kr   c                 l    	 t          t          j        | t          |          g          }|||_        |S r,   )r   r
   powerrA   r   )	func_namer=   r   r@   s       r   CallrE   ;   s3    
Y677DKr   c                  8    	 t          t          j        d          S )N
r   r   NEWLINEr   r   r   NewlinerJ   B   s    t$$$r   c                  8    	 t          t          j        d          S )N rH   r   r   r   	BlankLinerM   F   s    r"""r   c                 :    t          t          j        | |          S r'   )r   r   NUMBER)nr   s     r   NumberrQ   J   s    a////r   c           	          	 t          t          j        t          t          j        d          | t          t          j        d          g          S )N[])r   r
   r-   r   r   LBRACERBRACE)
index_nodes    r   	SubscriptrX   M   s@    'tEL#66)#EL#668 9 9 9r   c                 <    	 t          t          j        | |          S r'   )r   r   STRING)stringr   s     r   Stringr\   S   s    fV4444r   c           	      r   	 d| _         d|_         d|_         t          t          j        d          }d|_         t          t          j        d          }d|_         ||||g}|rWd|_         t          t          j        d          }d|_         |                    t          t          j        ||g                     t          t          j        | t          t          j	        |          g          }t          t          j
        t          t          j        d          |t          t          j        d          g          S )NrL   r   forinifrS   rT   )r   r   r   r(   appendr   r
   comp_if	listmakercomp_forr"   rU   rV   )	xpfpittestfor_leafin_leaf
inner_argsif_leafinners	            r   ListComprn   W   s    BIBIBIEJ&&HHO5:t$$GGNB,J ?uz4(($t|gt_==>>>"d4=*&E&E!FGGE	U\3//U\3//12 2 2r   c                 B   	 |D ]}|                                  t          t          j        d          t          t          j        | d          t          t          j        dd          t	          t
          j        |          g}t	          t
          j        |          }|S )Nfromr   r   import)remover   r   r(   r   r
   import_as_namesimport_from)package_name
name_leafsleafchildrenimps        r   
FromImportrz   o   s    *   UZ((UZc:::UZ#666T):668H t
*
*CJr   c                 n   	 |d                                          }|j        t          j        k    r|                                 }n-t	          t          j        |                                 g          }|d         }|rd |D             }t	          t          j        t          t          |d                   t          |d                             t	          t          j        |d                                          ||d                                          g          gz   |z             }| j	        |_	        |S )Nr/   afterc                 6    g | ]}|                                 S r   )r:   ).0rP   s     r   
<listcomp>z!ImportAndCall.<locals>.<listcomp>   s     ***q***r       r   lparrpar)
r:   typer
   r<   r   rC   r1   r*   r-   r   )r@   resultsnamesr/   
newarglistr|   news          r   ImportAndCallr      s   
 %.


 
 C
x4<YY[[

$,66
GE +**E***
tzDqNNDqNN33T\fo++-- fo++--/0 0 11 49	9: :C CJJr   c                    	 t          | t                    r'| j        t                      t	                      gk    rdS t          | t                    ot          | j                  dk    ot          | j        d         t                    okt          | j        d         t                    oKt          | j        d         t                    o+| j        d         j        dk    o| j        d         j        dk    S )NT   r   r      r   r   )r    r   rx   r   r   lenr   r   r@   s    r   is_tupler      s    2$ $-FHHfhh3G"G"GttT"" .DM""a'.4=+T22. 4=+T22. 4=+T22	.
 a &#-. a &#-/r   c                 6   	 t          | t                    ot          | j                  dk    okt          | j        d         t                    oKt          | j        d         t                    o+| j        d         j        dk    o| j        d         j        dk    S )Nr   r   rS   rT   )r    r   r   rx   r   r   r   s    r   is_listr      s    1tT"" /DM""Q&/4=+T22/ 4=,d33/ a &#-	/
 b!'3.0r   c                 l    t          t          j        t                      | t	                      g          S r,   )r   r
   r"   r   r   r   s    r   parenthesizer      s#    	FHHdFHH5666r   >
   allanymaxminsetsumr!   tuplesorted	enumeratec              #   `   K   	 t          | |          }|r|V  t          ||          }|d S d S r,   )getattr)r/   r0   nexts      r   
attr_chainr      sZ       3D
 #


tT""  # # # # #r   zefor_stmt< 'for' any 'in' node=any ':' any* >
        | comp_for< 'for' any 'in' node=any any* >
     z
power<
    ( 'iter' | 'list' | 'tuple' | 'sorted' | 'set' | 'sum' |
      'any' | 'all' | 'enumerate' | (any* trailer< '.' 'join' >) )
    trailer< '(' node=any ')' >
    any*
>
z`
power<
    ( 'sorted' | 'enumerate' )
    trailer< '(' arglist<node=any any*> ')' >
    any*
>
Fc                 j   	 t           sMt          j        t                    at          j        t                    at          j        t
                    ada t          t          t
          g}t          |t          | d                    D ]*\  }}i }|                    ||          r|d         | u r dS +dS )NTparentr@   F)	
pats_builtr   compile_patternp0p1p2zipr   match)r@   patternspatternr   r   s        r   in_special_contextr      s      $R(($R(($R((
B|HxD()C)CDD  ==)) 	gfo.E.E445r   c                    	 | j         }||j        t          j        k    rdS | j        }|j        t
          j        t
          j        fv rdS |j        t
          j        k    r|j	        d         | u rdS |j        t
          j
        k    s;|j        t
          j        k    r(||j        t          j        k    s|j	        d         | u rdS dS )NFr   T)prev_siblingr   r   r8   r   r
   funcdefclassdef	expr_stmtrx   
parameterstypedargslistr4   )r@   prevr   s      r   is_probably_builtinr      s     DDI22u[F{t|T]333u{dn$$);t)C)Cu{do%%[D...$)u{":":OA$&& u4r   c                     	 | _| j         t          j        k    rAt          | j                  dk    r)| j        d         }|j         t
          j        k    r|j        S | j        } | _dS )Nr   r   rL   )	r   r
   suiter   rx   r   INDENTr   r   )r@   indents     r   find_indentationr     sg    )

9
""s4='9'9A'='=]1%F{el**|#{ 
 2r   c                     | j         t          j        k    r| S |                                 } | j        d c}| _        t          t          j        | g          }||_        |S r,   )r   r
   r   r:   r   r   )r@   r   r   s      r   
make_suiter     sR    yDJ::<<D+tFDKdV$$EELLr   c                     	 | j         t          j        k    r-| j        } | st	          d          | j         t          j        k    -| S )Nz,root found before file_input node was found.)r   r
   
file_inputr   
ValueErrorr   s    r   	find_rootr   &  sK    '
)t
&
&{ 	MKLLL )t
&
& Kr   c                 ^    	 t          |t          |          |           }t          |          S r,   )find_bindingr   bool)packager)   r@   bindings       r   does_tree_importr   /  s,    9 44'::G==r   c                 B    	 | j         t          j        t          j        fv S r,   )r   r
   import_namert   r   s    r   	is_importr   7  s    :9)4+;<<<r   c           	      H   	 d }t          |          }t          | ||          rd S dx}}t          |j                  D ]E\  }} ||          st          |j        |d                    D ]\  }} ||          s n||z   } |dk    r]t          |j                  D ]H\  }}|j        t
          j        k    r.|j        r'|j        d         j        t          j        k    r|dz   } nI| Ot          t
          j
        t          t          j        d          t          t          j        |d          g          }	n+t          | t          t          j        |d          g          }	|	t                      g}
|                    |t          t
          j        |
                     d S )Nc                 n    | j         t          j        k    o | j        ot	          | j        d                   S )Nr   )r   r
   simple_stmtrx   r   r   s    r   is_import_stmtz$touch_import.<locals>.is_import_stmt>  s4    	T-- ,$- ,$-*++	-r   r   r   rq   r   r   )r   r   r   rx   r   r
   r   r   rZ   r   r   r   r(   rz   rJ   r;   )r   r)   r@   r   root
insert_posoffsetidxnode2import_rx   s              r   touch_importr   ;  s   $- - - T??Dt,,  Jt}--  	T~d## 	&t}STT':;; 	 	MFE!>%(( 6\
 Q"4=11 	 	IC	T---$--}Q$44 1W
t'X&&T#...*
  
 WtEJS'I'I'I&JKK#Hj$t'7"B"BCCCCCr   c           
      R   	 |j         D ]}d }|j        t          j        k    rNt	          | |j         d                   r|c S t          | t          |j         d                   |          }|r|}n|j        t          j        t          j        fv r/t          | t          |j         d                   |          }|r|}nK|j        t          j	        k    rt          | t          |j         d                   |          }|r|}nt          |j         dd                    D ]U\  }}|j        t          j        k    r;|j        dk    r0t          | t          |j         |dz                      |          }|r|}Vn|j        t          v r|j         d         j        | k    r|}nmt          || |          r|}nY|j        t          j        k    rt          | ||          }n2|j        t          j        k    rt	          | |j         d                   r|}|r|s|c S t%          |          r|c S d S )Nr   r   r   r   :   r   )rx   r   r
   for_stmt_findr   r   if_stmt
while_stmttry_stmtr   r   COLONr   	_def_syms_is_import_bindingr   r   r   )r)   r@   r   childretrP   ikids           r   r   r   i  s8   (  " ":&&T5>!,-- T:enR.@#A#A7KKAM#ZDL$/:::T:enR.@#A#A7KKAM#Z4=((T:enQ.?#@#@'JJA &'qrr(:;; & &FAsx5;..393C3C(z%.1:M/N/NPWXXAc	&
 Z9$$):)@D)H)HCCtW55 	CCZ4+++tUG44CCZ4>))T5>!,--  	 


~~ 


4r   c                     |g}|rl|                                 }|j        dk    r)|j        t          vr|                    |j                   n"|j        t
          j        k    r|j        | k    r|S |ld S )N   )popr   _block_symsextendrx   r   r(   r   )r)   r@   nodess      r   r   r     s}    FE
 yy{{9s??ty;;LL''''Y%*$$t););K   4r   c                 0   	 | j         t          j        k    r|s| j        d         }|j         t          j        k    r`|j        D ]V}|j         t          j        k    r|j        d         j        |k    r| c S 2|j         t          j        k    r|j        |k    r| c S Wn{|j         t          j        k    r1|j        d         }|j         t          j        k    r|j        |k    r| S n5|j         t          j        k    r|j        |k    r| S n| j         t          j	        k    r|r2t          | j        d                                                   |k    rd S | j        d         }|rt          d|          rd S |j         t          j        k    rt          ||          r| S |j         t          j        k    r0|j        d         }|j         t          j        k    r|j        |k    r| S n;|j         t          j        k    r|j        |k    r| S |r|j         t          j        k    r| S d S )Nr   r   r   r   as)r   r
   r   rx   dotted_as_namesdotted_as_namer   r   r(   rt   strstripr   rs   import_as_nameSTAR)r@   r)   r   ry   r   lastrP   s          r   r   r     s   ) yD$$$W$mA8t+++    :!444~a(.$66# 7Z5:--%+2E2EKKK  X,,,<#DyEJ&&4:+=+=X##	T(9(9K	d&	&	&  	s4=+,,2244??4M! 	uT1~~ 	4Vt+++dA+KVt***JqMEzUZ''EK4,?,?Vuz!!agooK 	5:--K4r   r,   )NN)5pgen2r   pytreer   r   pygramr   r
   rL   r   r   r   r   r%   r*   r1   r5   r.   rA   rE   rJ   rM   rQ   rX   r\   rn   rz   r   r   r   r   consuming_callsr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r-   r   r   r   r   r   r   <module>r      s   7               * * * * * *      : : :! ! !! ! !	H 	H 	H1 1 1 14 4 4" " "       &&((       % % %# # #0 0 0 09 9 95 5 5 52 2 2 20  &  8
/ 
/ 
/0 0 07 7 7. . .# # #&	 
  &  .        = = =*D *D *DZ ]DL)	( ( ( (T |T]DL9  ' ' ' ' ' 'r   