
    `i }                         d Z ddlZddlZddlZddlZddlmZmZmZ ddl	m
Z
 ddlmZ ddlmZ dd	eedfd
Zej        eeefdZ e            Z G d de          Z G d de
          ZdS )aw  
Part of the astor library for Python AST manipulation.

License: 3-clause BSD

Copyright (c) 2008      Armin Ronacher
Copyright (c) 2012-2017 Patrick Maupin
Copyright (c) 2013-2017 Berker Peksag

This module converts an AST into Python source code.

Before being version-controlled as part of astor,
this code came from here (in 2012):

    https://gist.github.com/1250562

    N   )get_op_symbolget_op_precedence
Precedence)ExplicitNodeVisitor)pretty_string)pretty_sourcez    Fc                    |t           }nGt          j        |          st          d          t	          |t                     st          d           ||||          }|                    |            |j                            d           t          |j        d                   t          d          k    r
d|j        d<    ||j                  S )a  This function can convert a node tree back into python sourcecode.
    This is useful for debugging purposes, especially if you're dealing with
    custom asts not generated by python itself.

    It could be that the sourcecode is evaluable when the AST itself is not
    compilable / evaluable.  The reason for this is that the AST contains some
    more data than regular sourcecode does, which is dropped during
    conversion.

    Each level of indentation is replaced with `indent_with`.  Per default this
    parameter is equal to four spaces as suggested by PEP 8, but it might be
    adjusted to match the application's styleguide.

    If `add_line_information` is set to `True` comments for the line numbers
    of the nodes are added to the output.  This can be used to spot wrong line
    number information of statement nodes.

    `source_generator_class` defaults to `SourceGenerator`, and specifies the
    class that will be instantiated and used to generate the source code.

    Nz(source_generator_class should be a classz>source_generator_class should be a subclass of SourceGenerator
r    )	SourceGeneratorinspectisclass	TypeError
issubclassvisitresultappendset)nodeindent_withadd_line_informationr   r	   source_generator_class	generators          b/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/astor/code_gen.py	to_sourcer      s    0 %!0_344 ZBCCC.@@ ZXYYY&&)=: :IOODD!!!
9A3t99,, 	=)***    c                 "      fdS )z This only uses a closure for performance reasons,
        to reduce the number of attribute lookups.  (set_precedence
        is called a lot of times.)
    c                      |           r |           } |D ]8} |          r| |_          |          r
 | g|R   ,|
J |            9dS )z>Set the precedence (of the parent) into the children.
        N)_pp)valuenodesr   ASTr   
isinstancelistset_precedences      r   r&   z)precedence_setter.<locals>.set_precedenceM   s     :eS!! 	-%%e,,E 	* 	*Dz$$$ * D$'' *u,t,,,,,||T||||	* 	*r    )r#   r   r$   r%   r&   s   ````@r   precedence_setterr(   F   s<    * * * * * * * * * r   c                   (    e Zd ZdZdZd Zd Zd ZdS )DelimitzA context manager that can add enclosing
       delimiters around the output of a
       SourceGenerator method.  By default, the
       parentheses are added, but the enclosed code
       may set discard=True to get rid of them.
    Fc                 ~   d}d}d}|D ]&}t          |t          j                  r||}!|}$|}'|                    |d                    |j        x}| _        t          |          | _        |d         | _        |At          |p|          x| _	        }|
                    |          x| _        }	||	k    | _        dS dS )z use write instead of using result directly
            for initial data, because it may flush
            preceding data into result.
        z()Nr   r   )r$   astr#   writer   lenindexclosingr   pget__ppppdiscard)
selftreeargs
delimitersr   opargr   r1   r3   s
             r   __init__zDelimit.__init__j   s    
 
 	! 	!C#sw'' !<DDBB 



:a=!!!#{*[[
!!}*2:666DFQ<<---DGb7DLLL r   c                     | S Nr'   )r5   s    r   	__enter__zDelimit.__enter__   s    r   c                 x    | j         }| j        dz
  }| j        rd||<   d S |                    | j                   d S )Nr   r   )r   r/   r4   r   r0   )r5   exc_infor   starts       r   __exit__zDelimit.__exit__   sE    
Q< 	(F5MMMMM$,'''''r   N)__name__
__module____qualname____doc__r4   r;   r>   rB   r'   r   r   r*   r*   `   sR          G# # #2  ( ( ( ( (r   r*   c                   r   e Zd ZdZdZdeeeefdZ	 e
dej                  j        fdZd Zd Zd\dZd Zd Zd Zd Zd Zd Zd]dZd Zd Zd Zd Zd Zd Zd]dZd Z d Z!d Z"d]dZ#d Z$d Z%d]d Z&d! Z'd" Z(d# Z)d$ Z*d% Z+d& Z,d' Z-d( Z.d) Z/d* Z0d+ Z1d, Z2d- Z3d. Z4d/ Z5d0 Z6d1 Z7d2 Z8d3 Z9efd4Z:d5 Z;d6 Z<d7 Z=d]d8Z>d9 Z?d: Z@d; ZAeBjC        d<k    fd=ZDd> ZEd? ZFd@ ZGdA ZHdB ZIdC ZJdD ZKdE ZLdF ZMdG ZNdH ZOdI ZPdJ ZQdK ZRdL ZSdM ZTdN ZUdO ZVdP ZWdQ ZXdR ZYdS ZZdT Z[dU Z\dV Z]dW Z^e^Z_dX Z`dY ZadZ Zbd[ Zcd	S )^r   zThis visitor is able to transform a well formed syntax tree into Python
    sourcecode.

    For more details have a look at the docstring of the `node_to_source`
    function.

    Fc                     	
 g  _         | _        | _        d _        d _        d _        | _        t          j         j	         j         

j
        		
 fd}| _        d S )Nr   )r   r   c                     | D ]} |          r 	|            |          r |             0j         rD dj         z                        df_         j        j        z             d_         |r |           dS )zr self.write is a closure for performance (to reduce the number
                of attribute lookups).
            r   r   N)	new_linescolinfor   indentation)
paramsitemr#   r   callabler$   r.   r   r5   r   s
     r   r-   z'SourceGenerator.__init__.<locals>.write   s      % %:dC(( %E$KKKKXd^^ 	%DFFFF~ +tdn4555'*s6{{A~t/$2BBCCC)* %t% %r   )r   r   r   rL   rJ   rK   r   r,   r#   r   r   r-   )r5   r   r   r   r.   r$   rO   r-   r#   r   r   r   s   `   ``` @@@@r   r;   zSourceGenerator.__init__   s     &$8!*g
	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	%$ 


r   r'   )keywordsr    c                     |                     d          st          t          |dd          |          fd}t          | ||           |S )za Get an attribute of the node.
            like dict.get (returns None if doesn't exist)
        get_   Nc                      |           S r=   r'   )r   defaultgeta	shortnames    r   getterz+SourceGenerator.__getattr__.<locals>.getter   s    4i111r   )
startswithAttributeErrorgetattrsetattr)r5   namedefaultsrX   rU   rV   rW   s       @@@r   __getattr__zSourceGenerator.__getattr__   s~    
 v&& 	!  H	(9%%	2 	2 	2 	2 	2 	2 	2 	dF###r   c                     t          | g|R  S r=   )r*   )r5   r7   s     r   delimitzSourceGenerator.delimit   s    t#d####r   c                 .    |d          | j         |  dS d S )NTr-   )r5   stuffs     r   conditional_writez!SourceGenerator.conditional_write   s(    9 DJ4 ! r   Nr   c                     t          | j        d|z             | _        |-| j        r(|                     d|j        z             d| _        d S d S d S )Nr   z
# line: %s)maxrJ   r   r-   lineno)r5   r   extras      r   newlinezSourceGenerator.newline   sY    T^QY77 9JJ|dk1222DNNN r   c                 Z    | xj         dz  c_          | j        |  | xj         dz  c_         d S Nr   )rL   r-   )r5   
statementss     r   bodyzSourceGenerator.body   s?    A
JAr   c                 n    |r2|                      | j        d           |                     |           d S d S )Nzelse:)r-   rk   ro   )r5   elsewhats     r   	else_bodyzSourceGenerator.else_body   sB     	 JJt|W---IIh	  	 r   c                 n    |                      |j                    |                     |j                   d S r=   )ro   rr   orelser5   r   s     r   body_or_elsezSourceGenerator.body_or_else   s0    		$)t{#####r   c                 >    g  fd fd}t          |dg           }d}|r[|t          |j                  t          |j                  z
  z  } |||j        d |                                         d            ||j        |j        |d                                          d|j                                        |          }|r.|j                             d            |||j                                        d|j	                   d S )Nc                  d    r                      d           d S                     d           d S N, Tr-   r   )r5   
want_commas   r   write_commaz4SourceGenerator.visit_arguments.<locals>.write_comma   s=     (

4     !!$'''''r   c                    t          t          j        |           d gt          |           t          |          z
  z  }t	          | ||z             D ]1\  }}                    |                               d|           2d S )N=)r&   r   Commar.   zipr-   rf   )r7   r^   paddingr:   rU   r5   r}   s        r   	loop_argsz2SourceGenerator.visit_arguments.<locals>.loop_args   s    :+X666fD		CMM 9:G #D'H*< = = 5 5W

;,,,&&sG44445 5r   posonlyargsr   /***)
r[   r.   r^   r7   r-   rf   varargget_kwonlyargskw_defaultskwarg)r5   r   r   r   offset
kwonlyargsr|   r}   s   `     @@r   visit_argumentszSourceGenerator.visit_arguments   s]   
	( 	( 	( 	( 	( 	(	5 	5 	5 	5 	5 	5 dM266 	)c$-((3ty>>99FIk4=&#9:::JJ{C(((	$)T]6773444{C===((..
 	4{"

;,,,Ij$"2333{D$*=====r   c                 D    |                      |            | j        |  d S r=   )rk   r-   )r5   r   rM   kws       r   	statementzSourceGenerator.statement  s)    T
Fr   c                 t    |                      |           |j        D ]}|                     |d|           d S )Nrj   @)rk   decorator_listr   )r5   r   rj   	decorators       r   
decoratorszSourceGenerator.decorators  sK    5!!!, 	6 	6INN9c95555	6 	6r   c                     t          t          j        g|R   t          |          D ]\  }}|                     |rdnd|            |                     |rdnd           d S )Nrz   r   ,)r&   r   r   	enumerater-   )r5   itemstrailingidxrN   s        r   
comma_listzSourceGenerator.comma_list  sw    z'0%0000"5)) 	2 	2ICJJs*ttD1111

(*33+++++r   c                     t          ||j        g|j        R   |                     |           |j        D ]}|                     |d           |                     |j                   d S )N = )r&   r!   targetsrk   r-   r   )r5   r   targets      r   visit_AssignzSourceGenerator.visit_Assign   sr    tTZ7$,7777Tl 	& 	&FJJvu%%%%

4:r   c                     t          ||j        |j                   |                     ||j        t	          |j        d          |j                   d S )Nz %s= )r&   r!   r   r   r   r9   ru   s     r   visit_AugAssignzSourceGenerator.visit_AugAssign'  sQ    tTZ555tT[-*I*Iz	# 	# 	# 	# 	#r   c                 ^   t          ||j        |j                   t          t          j        |j                   t          |j        t          j                  o|j	         }|rdnd}|rdnd}| 
                    |||j        |d|j                   |                     d|j                   d S )N(r   ): r   )r&   r   
annotationr   r   r!   r$   r,   Namesimpler   rf   )r5   r   need_parensbeginends        r   visit_AnnAssignzSourceGenerator.visit_AnnAssign,  s    tT[$/:::z'444 ch77KO"* (ccbtUDKdDOLLLudj11111r   c                     |                      |d|j        dz  |j        pdd           |                     |j                   |j        dk    rdd |j        D             v rd| _        d S d S d S )	Nzfrom .r   z import 
__future__unicode_literalsc              3   $   K   | ]}|j         V  d S r=   )r]   .0xs     r   	<genexpr>z3SourceGenerator.visit_ImportFrom.<locals>.<genexpr>:  s=       B, B,B, B, B, B, B, B,r   T)r   levelmoduler   namesusing_unicode_literalsru   s     r   visit_ImportFromz SourceGenerator.visit_ImportFrom5  s    tWdj3&6{(b*	6 	6 	6
###;,&&+= B, B, $
B, B, B, ,, ,,*.D''' '& ,, ,,r   c                 f    |                      |d           |                     |j                   d S )Nzimport )r   r   r   ru   s     r   visit_ImportzSourceGenerator.visit_Import>  s0    tY'''
#####r   c                     t          ||j                   |                     |           |                     |           d S r=   )r&   r!   r   generic_visitru   s     r   
visit_ExprzSourceGenerator.visit_ExprB  s@    tTZ(((t4     r   c                    |rdnd}|                      || j        rdnd           |                     ||d|j        d           |                     |j                   |                     d           |                     d|                     |                     |                     d	           | 	                    |j	                   | j        s| 
                    d
           d S d S )Nasync r   r      zdef r   r   z ->:r   )r   rL   r   r]   r   r7   r-   rf   get_returnsro   rk   r5   r   is_asyncprefixs       r   visit_FunctionDefz!SourceGenerator.visit_FunctionDefG  s    %-24#3:aa;;;t666499=sCCCTY'''

3ud&6&6t&<&<===

3		$) 	"LLqL!!!!!	" 	"r   c                 4    |                      |d           d S NT)r   )r   ru   s     r   visit_AsyncFunctionDefz&SourceGenerator.visit_AsyncFunctionDefT  s!    td33333r   c                     g  fd}                      |d                                |d|j        z             |j        D ]}                     ||                                |          D ]/}                     ||j        pd|j        rdnd|j                   0                     |d 	                    |                                          |d 
                    |                                          rdpd	                                |j                    j        s                     d
           d S d S )Nc                       r                     d           d S                      d                                d           d S )Nrz   Tr   r{   )	have_argsr5   s   r   paren_or_commaz6SourceGenerator.visit_ClassDef.<locals>.paren_or_commaZ  sJ      

4       &&&

3r   r   zclass %sr   r   r   r   z):r   r   )r   r   r]   basesr-   get_keywordsr:   r!   rf   get_starargs
get_kwargsro   rL   rk   )r5   r   r   basekeywordr   s   `    @r   visit_ClassDefzSourceGenerator.visit_ClassDefW  s   		  	  	  	  	  	  	a   tZ$)3444J 	- 	-DJJ~t,,,,((.. 	D 	DGJJ~w{'8b%k3sstW]D D D D~sD4E4Ed4K4KLLL~tT__T5J5JKKK

9%,---		$) 	"LLqL!!!!!	" 	"r   c                    t          ||j                   |                     |d|j        d           |                     |j                   	 |j        }t          |          dk    rzt          |d         t          j                  rZ|d         }t          ||j                   | 	                    | j
        d|j        d           |                     |j                   n|                     |           d S )Nzif r   Tr   r   zelif )r&   testr   ro   rt   r.   r$   r,   Ifr-   rk   rr   )r5   r   else_s      r   visit_IfzSourceGenerator.visit_Ifp  s    tTY'''tUDIs333		$)		KE5zzQ:eAh#?#?QxtTY///

4<$)SAAA		$)$$$$u%%%		r   c                     t          ||j                   |rdnd}|                     |d|z  |j        d|j        d           |                     |           d S )Nr   r   z%sfor  in r   )r&   r   r   iterrv   r   s       r   	visit_ForzSourceGenerator.visit_For  sh    tT[)))%-2tX.{FDIs	< 	< 	<$r   c                 4    |                      |d           d S r   )r   ru   s     r   visit_AsyncForzSourceGenerator.visit_AsyncFor  s    td+++++r   c                     t          ||j                   |                     |d|j        d           |                     |           d S )Nzwhile r   )r&   r   r   rv   ru   s     r   visit_WhilezSourceGenerator.visit_While  sH    tTY'''tXty#666$r   c                 "   |rdnd}|                      |d|z             t          |d          r|                     |           n|                     |j                   |                     d           |                     |j                   d S )Nr   r   z%swith context_exprr   )r   hasattrvisit_withitemr   r   r-   ro   r   s       r   
visit_WithzSourceGenerator.visit_With  s    %-2tY/0004(( 	(%%%%OODJ'''

3		$)r   c                 4    |                      |d           d S r   )r   ru   s     r   visit_AsyncWithzSourceGenerator.visit_AsyncWith  s    t,,,,,r   c                 p    |                      |j                   |                     d|j                   d S N as )r-   r   rf   optional_varsru   s     r   r   zSourceGenerator.visit_withitem  s6    

4$%%%vt'9:::::r   c                 T    |                      t          |j                             d S r=   )r-   reprr!   ru   s     r   visit_NameConstantz"SourceGenerator.visit_NameConstant  s$    

4
##$$$$$r   c                 2    |                      |d           d S )Npassr   ru   s     r   
visit_PasszSourceGenerator.visit_Pass  s    tV$$$$$r   c                     |                      |d           |j        }|j        %|                     d           |j        g|j        z   }|                     ||j                    d S )Nzprint z >> )r   valuesdestr-   r   nl)r5   r   r   s      r   visit_PrintzSourceGenerator.visit_Print  se    tX&&&9 JJvi[4;.FDG,,,,,r   c                 f    |                      |d           |                     |j                   d S )Nzdel )r   r   r   ru   s     r   visit_DeletezSourceGenerator.visit_Delete  s0    tV$$$%%%%%r   c                     |                      |d           |                     |j                    | j        |j          |                     |j                   d S )Ntry:)r   ro   r-   handlersrr   rt   ru   s     r   visit_TryExceptzSourceGenerator.visit_TryExcept  sU    tV$$$		$)
DM""t{#####r   c                 *   |                      |d           |                     |j                    | j        |j          |                     |j                   |j        r2|                      |d           |                     |j                   d S d S Nr  zfinally:)r   ro   r-   r  rr   rt   	finalbodyru   s     r   	visit_TryzSourceGenerator.visit_Try  s    tV$$$		$)
DM""t{###> 	&NN4,,,IIdn%%%%%	& 	&r   c                     |                      |d           |                     d|j                  r|                     d|j                   |                     d           |                     |j                   d S )Nexcept r   r   )r   rf   typer]   r-   ro   ru   s     r   visit_ExceptHandlerz#SourceGenerator.visit_ExceptHandler  sq    tX&&&!!#ty11 	6""649555

3		$)r   c                     |                      |d           |                     |j                   |                      |d           |                     |j                   d S r  )r   ro   r  ru   s     r   visit_TryFinallyz SourceGenerator.visit_TryFinally  sX    tV$$$		$)tZ(((		$.!!!!!r   c                     |j         |j        f}|d         |d d d         n|}|                     |d|j                   |                     d|d                    |                     d|d                    d S )Nr   rc   zexec r   rz   r   )globalslocalsr   ro   rf   )r5   r   dictss      r   
visit_ExeczSourceGenerator.visit_Exec  s~    dk)$Qx/dddUtWdi000vuQx000tU1X.....r   c                     t          ||j        |j                   |                     |d|j                   |                     d|j                   d S )Nzassert rz   )r&   r   msgr   rf   ru   s     r   visit_AssertzSourceGenerator.visit_Assert  sN    tTY111tY	222tTX.....r   c                 d    |                      |dd                    |j                             d S )Nzglobal rz   r   joinr   ru   s     r   visit_GlobalzSourceGenerator.visit_Global  s,    tY		$*(=(=>>>>>r   c                 d    |                      |dd                    |j                             d S )Nz	nonlocal rz   r  ru   s     r   visit_NonlocalzSourceGenerator.visit_Nonlocal  s,    t[$))DJ*?*?@@@@@r   c                     t          ||j                   |                     |d           |                     d|j                   d S )Nreturnr  )r&   r!   r   rf   ru   s     r   visit_ReturnzSourceGenerator.visit_Return  sF    tTZ(((tX&&&sDJ/////r   c                 2    |                      |d           d S )Nbreakr   ru   s     r   visit_BreakzSourceGenerator.visit_Break  s    tW%%%%%r   c                 2    |                      |d           d S )Ncontinuer   ru   s     r   visit_ContinuezSourceGenerator.visit_Continue  s    tZ(((((r   c                    |                      |d           |                     d|                     |                    r|                     d|j                   d S |                     d|                     |                    rMt          ||j                   |                     d|j                   |                     d|j                   d S d S )Nraiser  z from rz   )r   rf   get_exccauseget_typer&   insttbackru   s     r   visit_RaisezSourceGenerator.visit_Raise  s    tW%%%!!#t||D'9'9:: 	5""8TZ88888##Ct)<)<== 	54+++""4333""444444	5 	5r   c                 H    |                      |j        d|j                   d S )Nr   )r-   r!   attrru   s     r   visit_AttributezSourceGenerator.visit_Attribute  s"    

4:sDI.....r   c                    | j         g fd}|j        }|j        }|                     |          }|                     |          } ||           ||          z   }||d uz  }||d uz  }|dk    rt
          j        nt
          j        }	t          |	g|R   | 	                    |j
                    d           |D ]}
 ||
           t          t
          j        gd |D             R   |D ]"}|j        pd}
 ||
|
rdnd|j                   #|                     |d|           |                     |d|            d	           d S )
Nc                  P     r d           d S                       d           d S ry   )r   )r|   r-   s   r   r}   z/SourceGenerator.visit_Call.<locals>.write_comma  s6     (d!!$'''''r   r   r   c              3   $   K   | ]}|j         V  d S r=   )r!   r   s     r   r   z-SourceGenerator.visit_Call.<locals>.<genexpr>  s$      *E*Eq17*E*E*E*E*E*Er   r   r   r   r   r   )r-   r7   rP   r   r   r   r   call_one_argr&   r   funcr:   r!   rf   )r5   r   r.   r}   r7   rP   starargskwargsnumargsr1   r:   r   r|   r-   s               @@r   
visit_CallzSourceGenerator.visit_Call  s   

	( 	( 	( 	( 	( 	( y=$$T**&&#d))cc(mm+84''6%% '!J1Hq 4    

49c


 	$ 	$CE+s####z'F*E*EH*E*E*EFFFF 	I 	IG +#CE+s3$8CCD'-HHHH{C:::{D&999c




r   c                 :    |                      |j                   d S r=   )r-   idru   s     r   
visit_NamezSourceGenerator.visit_Name"  s    

47r   c                    |j         }t          |t          t          t          f          rE|                     |          5  |                     |           d d d            d S # 1 swxY w Y   d S t          |t                    r|                     ||j                    d S |t          u r| 
                    d           d S | 
                    t          |                     d S Nz...)r!   r$   intfloatcomplexra   _handle_numeric_constantstr_handle_string_constantEllipsisr-   r   )r5   r   r!   s      r   visit_ConstantzSourceGenerator.visit_Constant'  s   
ec5'233 	$d## 5 5--e4445 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5s## 	$((tz:::::hJJuJJtE{{#####s   A""A&)A&c                 6    |                      |d d           d S )NT)	is_joined)rE  ru   s     r   visit_JoinedStrzSourceGenerator.visit_JoinedStr4  s#    $$T44$@@@@@r   c                 V                          |          }|t          j        k    |t          j        k    z   }                     d            j        } j        \  }} j        |d          }	|r|	d         |d          |	d<   d                    |	          }	t          j	        dk    |rd fdt          |          }
 |                                d           d                    ||
d                    }||
d = ||f _        d}n|
J d            |} j        }                     |||	|          }|rd|z   }nt          |dd          r
|j        |z   }                     |           |                    d	          d
z   }|rt          |          d
z
  |f _        d S d S )Nr   r   )      c                    | j         D ]}t          |t          j                  rC                    |j                            dd                              dd                     `t          |t          j                  r                    d          5  t          |dd           r                    |j
                   n/t          ||j                                       |j                   |j        dk    r*                    dt          |j                  z             |j        %                    d	            |j                   d d d            n# 1 swxY w Y   er6t          |t          j                  r                    |j                   t%          |          j        }J d|z              d S )N{z{{}z}}{}	expr_textrc   z!%sr   Fz Invalid node %s inside JoinedStr)r   r$   r,   Strr-   sreplaceFormattedValuera   r[   rR  r&   r!   r   
conversionchrformat_specConstantr  rC   )r   r!   kindhas_ast_constantrecurser5   s      r   r]  z8SourceGenerator._handle_string_constant.<locals>.recurseU  s   ![ P PE!%11 P

57??3#=#=#E#Ec4#P#PQQQQ#E3+=>> P!\\$// ; ;&uk4@@ 8 $

5? ; ; ; ; .uek B B B $

5; 7 7 7$/255 $

53u7G3H3H+H I I I$0< $

3 '(9 : : :; ; ; ; ; ; ; ; ; ; ; ; ; ; ; * Pj.M.M P

5;////#E{{3O&H4&OOOu+P Ps   B=E!!E%	(E%	FzNode value cannot be Nonefr[  r   r   )r2   r   ExprAssignr-   r   rK   r  sysversion_infor.   r   r   r[   r[  rfind)r5   r   r!   rI  
precedenceembeddedr   	res_index	str_indexcurrent_liner/   mystruni_litlfr\  r]  s   `             @@r   rE  z'SourceGenerator._handle_string_constant7  s    \\$''
*/1:#446
 	

2  $|	9{9::. 	:*1oijj9LOww|,,+v5 *	2
P P P P P P P0 KKEGDMMM JJrNNNGGF566N++Euvv$i/DLGG $$&A$$$E1G""5(L'JJ 	&%KEET65)) 	&I%E

5[[" 	/v;;?B.DLLL	/ 	/r   c                 <    |                      ||j                   d S r=   )rE  rT  ru   s     r   	visit_StrzSourceGenerator.visit_Str  s     $$T4622222r   c                 T    |                      t          |j                             d S r=   )r-   r   rT  ru   s     r   visit_ByteszSourceGenerator.visit_Bytes  s"    

4<<     r   c                 h   |}d } |t          |t                    r|j        n|d          }t          |t                    rW ||j        d          }|j        dk    r|}n9|j        dk    rd|z  }n(d|dd	g|                    d
                   |d}n|}|                     |           d S )Nc                     |rdnd}	 t          j        |           r| dk     rd|z   S d|z   S t          j        |           r	d|d|dS n# t          $ r Y nw xY wt	          |           |z   S )Njr   r   z-1e10001e1000z(1e1000r   )mathisinfisnanOverflowErrorr   )r1   	imaginaryrT  s      r   partz6SourceGenerator._handle_numeric_constant.<locals>.part  s     (bA
:a== (1uu(1},#a<':a== : :45AAqqq99:      77Q;s   A
 A
 A
 

AAF)rx  Tr   z(%s+0j)r   +r   -r   )r$   rB  realimagrY   r-   )r5   r!   r   ry  r|  r}  rT  s          r   rC  z(SourceGenerator._handle_numeric_constant  s    	 	 	  tjG44;AFF!uMMMa!! 
	4$///Dv{{1$  #'$b	$//#2F2F(G(GNA

1r   )rL  r   c                    |                      |          5 }|                     |j                   |s|j        rzt	          |j        t
                    s+|j        dk     r t          j        dz   }|j        |k    |_        n5| 	                    |          }t	          |t          j                   |_        d d d            d S # 1 swxY w Y   d S )Nr   r   )ra   rC  nr4   r$   rB  r   Powr3   	get__p_opr,   USub)r5   r   newr8   pow_lhsr9   s         r   	visit_NumzSourceGenerator.visit_Num  s    \\$ 	F:))$&111  F:- F!$&'22 Ftvzz(nq0G)3')AJ&&--B-7CH-E-E)EJ&!	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   BCCCc                     |                      |          5 }|j        }|j        o||_        |                     |t	          |          dk               d d d            d S # 1 swxY w Y   d S rm   )ra   eltsr4   r   r.   )r5   r   r8   r  s       r   visit_TuplezSourceGenerator.visit_Tuple  s    \\$ 	2: 9D!+!3!<JOOD#d))q.111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   =A  A$'A$c                     |                      d          5  |                     |j                   d d d            d S # 1 swxY w Y   d S Nz[])ra   r   r  ru   s     r   
visit_ListzSourceGenerator.visit_List  s    \\$ 	' 	'OODI&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	'   >AAc                     |j         rJ|                     d          5  |                     |j                    d d d            d S # 1 swxY w Y   d S |                     d           d S )NrQ  z{1}.__class__())r  ra   r   r-   ru   s     r   	visit_SetzSourceGenerator.visit_Set  s    9 	*d## + +	***+ + + + + + + + + + + + + + + + + + JJ()))))s   AA	A	c                 D   t          t          j        g|j        R   |                     d          5  t          t          |j        |j                            D ],\  }\  }}|                     |rdnd|r|nd|rdnd|           -	 d d d            d S # 1 swxY w Y   d S )NrQ  rz   r   r   r   )	r&   r   r   r   ra   r   r   keysr-   )r5   r   r   keyr!   s        r   
visit_DictzSourceGenerator.visit_Dict  s   z'6$+6666\\$ 	9 	9%.s49dk/J/J%K%K 9 9!\c5

3.44B"%-332#&044D%9 9 9 99	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   ABBBc                    |j         |j        |j        }}}|                     ||          5 }t	          |t
          j                  }|j        }t          |rt          j        dz   n||           t          |rt          j
        n|dz   |           |                     |t          |d          |           d d d            d S # 1 swxY w Y   d S )Nr    %s )r9   leftrightra   r$   r,   r  r1   r&   r   PowRHSr-   r   )r5   r   r9   r  r  r8   ispowr1   s           r   visit_BinOpzSourceGenerator.visit_BinOp  s   '49dj%D\\$## 	?zr37++EA5?JNQ..aFFFB:,,AEEJJJJJt]2v66>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?s   B	CC	Cc                 6   |                      ||j                  5 }t          |j        d          }t          |j        dz   g|j        R   t          |j                  D ]\  }}|                     |r|pd|            	 d d d            d S # 1 swxY w Y   d S )Nr  r   r   )ra   r9   r   r&   r1   r   r   r-   )r5   r   r8   r9   r   r!   s         r   visit_BoolOpzSourceGenerator.visit_BoolOp  s    \\$(( 	4Jtw//B:<!+:dk::::'44 4 4
U

3:2+U33334	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   A$BBBc                 x   |                      ||j        d                   5 }t          |j        dz   |j        g|j        R   |                     |j                   t          |j        |j                  D ])\  }}|                     t          |d          |           *	 d d d            d S # 1 swxY w Y   d S )Nr   r   r  )
ra   opsr&   r1   r  comparatorsr   r   r-   r   )r5   r   r8   r9   r  s        r   visit_ComparezSourceGenerator.visit_Compare  s    \\$,, 	=
:<!+TYJ9IJJJJJJty!!! 4+;<< = =	E

=V44e<<<<=	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	= 	=s   A?B//B36B3c                    |                      |          5 }|j        }t          ||j                   t          |dz   |j                   d|_        |                     |j        d|j                   d d d            d S # 1 swxY w Y   d S )Nr   Fz := )ra   r1   r&   r   r!   r4   r-   )r5   r   r8   r1   s       r   visit_NamedExprzSourceGenerator.visit_NamedExpr  s    \\$ 	8:A1dk***1q5$*--- "'JJJt{FDJ777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8s   AB  BBc                 P   |                      ||j                  5 }t          |j        |j                   |j        |j        _        t          |j                  }|                     ||                                rdnd|j                   d d d            d S # 1 swxY w Y   d S )Nr  r   )	ra   r9   r&   r1   operand_p_opr   r-   isalpha)r5   r   r8   syms       r   visit_UnaryOpzSourceGenerator.visit_UnaryOp  s    \\$(( 	HJ:<666
 "&DL((CJJs3;;==8CCb$,GGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   A2BB"Bc                 t    t          ||j                   |                     |j        d|j        d           d S )N[])r&   slicer-   r!   ru   s     r   visit_SubscriptzSourceGenerator.visit_Subscript  s6    tTZ(((

4:sDJ44444r   c                    t          ||j        |j        |j                   |                     |j                   |                     d           |                     |j                   |j        `|                     d           t          |j        t          j                  r|j        j	        dk    s| 
                    |j                   d S d S d S )Nr   None)r&   loweruppersteprf   r-   r$   r,   r   r<  r   ru   s     r   visit_SlicezSourceGenerator.visit_Slice  s    tTZTY???tz***

3tz***9 JJsOOOty#(33 &ILF**

49%%%%%	 !  +*r   c                     |                      |          5 }t          |j        |j                   |                     |j                   d d d            d S # 1 swxY w Y   d S r=   )ra   r&   r1   r!   r   r5   r   r8   s      r   visit_IndexzSourceGenerator.visit_Index(  s    \\$ 	#::<444JJtz"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#s   5AAAc                 |    |j         }t          |g|R   |                     |t          |          dk               d S rm   )dimsr&   r   r.   )r5   r   r  s      r   visit_ExtSlicezSourceGenerator.visit_ExtSlice-  sC    yt#d####c$ii1n-----r   c                    |                      |          5  t          t          |          dz   |j                   |                     d           |                     d|j                   d d d            d S # 1 swxY w Y   d S )Nr   yieldr  )ra   r&   r   r!   r-   rf   ru   s     r   visit_YieldzSourceGenerator.visit_Yield2  s    \\$ 	4 	4,T22Q6
CCCJJw""3
333	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4s   AA99A= A=c                     |                      |          5  |                     d|j                   d d d            d S # 1 swxY w Y   d S )Nzyield from ra   r-   r!   ru   s     r   visit_YieldFromzSourceGenerator.visit_YieldFrom9  s    \\$ 	2 	2JJ}dj111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2   ?AAc                     |                      |          5  |                     d|j                   d d d            d S # 1 swxY w Y   d S )Nzawait r  ru   s     r   visit_AwaitzSourceGenerator.visit_Await>  s    \\$ 	- 	-JJx,,,	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-r  c                 *   |                      |          5 }t          |j        |j                   |                     d           |                     |j                   |                     d|j                   d d d            d S # 1 swxY w Y   d S )Nzlambda r   )ra   r&   r1   ro   r-   r   r7   r  s      r   visit_LambdazSourceGenerator.visit_LambdaB  s    \\$ 	(::<333JJy!!!  +++JJtTY'''		( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s   A%BBBc                 0    |                      d           d S r?  rd   ru   s     r   visit_EllipsiszSourceGenerator.visit_EllipsisI  s    

5r   c                     |                      d          5   | j        |j        g|j        R   d d d            d S # 1 swxY w Y   d S r  ra   r-   elt
generatorsru   s     r   visit_ListCompzSourceGenerator.visit_ListCompL      \\$ 	3 	3DJtx2$/2222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3   <A A c                    |                      |          5 }|j        t          j        k    rd|_        t          t          j        |j                    | j        |j        g|j	        R   d d d            d S # 1 swxY w Y   d S )NT)
ra   r3   r   r5  r4   r&   r   r  r-   r  r  s      r   visit_GeneratorExpz"SourceGenerator.visit_GeneratorExpP  s    \\$ 	3:}
 777%)
":+TX666DJtx2$/2222		3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   AA77A;>A;c                     |                      d          5   | j        |j        g|j        R   d d d            d S # 1 swxY w Y   d S )NrQ  r  ru   s     r   visit_SetCompzSourceGenerator.visit_SetCompW  r  r  c                     |                      d          5   | j        |j        d|j        g|j        R   d d d            d S # 1 swxY w Y   d S )NrQ  r   )ra   r-   r  r!   r  ru   s     r   visit_DictCompzSourceGenerator.visit_DictComp[  s    \\$ 	E 	EDJtxtzDDODDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es    AA
Ac                 ,   |                      |          5 }t          |j        dz   |j        |j                   t          |j        |j                   |                     |j        d|j        d|j                   d d d            d S # 1 swxY w Y   d S )Nr    if z else )ra   r&   r1   ro   r   rt   r-   r  s      r   visit_IfExpzSourceGenerator.visit_IfExp_  s    \\$ 	L::<!+TY	BBB:<555JJty&$)Xt{KKK	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	L 	Ls   A&B		BBc                 <    |                      d|j                   d S )Nr   )r-   r!   ru   s     r   visit_StarredzSourceGenerator.visit_Starrede  s    

3
#####r   c                     |                      d          5  |                     |j                   d d d            d S # 1 swxY w Y   d S )Nz``)ra   r   r!   ru   s     r   
visit_ReprzSourceGenerator.visit_Reprh  s    \\$ 	# 	#JJtz"""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#r  c                 $     | j         |j          d S r=   )r-   ro   ru   s     r   visit_ModulezSourceGenerator.visit_Modulem  s    
DIr   c                 :    |                      |j                   d S r=   )r   ro   ru   s     r   visit_Expressionz SourceGenerator.visit_Expressionr  s    

49r   c                 p    |                      |j                   |                     d|j                   d S )Nr   )r-   r:   rf   r   ru   s     r   	visit_argzSourceGenerator.visit_argw  s4    

48tT_55555r   c                 p    |                      |j                   |                     d|j                   d S r   )r-   r]   rf   asnameru   s     r   visit_aliaszSourceGenerator.visit_alias{  s4    

49vt{33333r   c                 *   t          ||j        g|j        R   t          t          j        |j                   |                     |          rdnd}|                     ||j        d|j                   |j        D ]}|                     d|           d S )Nz async for z for r   r  )r&   r   ifsr   comprehension_targetr   get_is_asyncr-   )r5   r   stmtif_s       r   visit_comprehensionz#SourceGenerator.visit_comprehension  s    tTY22222z6DDD $ 1 1$ 7 7D}}W

4fdi8888 	$ 	$CJJvs####	$ 	$r   )Nr   )F)drC   rD   rE   rF   r   r   r.   r$   rO   r;   dictr   highestgetr_   ra   rf   rk   ro   rr   rv   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r   r#  r&  r.  r1  r:  r=  rG  rJ  rE  rm  ro  rC  ra  rb  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  visit_Interactiver  r  r  r  r'   r   r   r   r      s         #9>,Z($ $ $ $L *.r"**, *, *,,/   "$ $ $       
     
$ $ $> > >B  6 6 6
, , , ,  # # #
2 2 2/ / /$ $ $! ! !

" 
" 
" 
"4 4 4" " "2         , , ,     
   - - -; ; ;
% % %% % %- - -& & &$ $ $& & &  " " "/ / // / /
? ? ?A A A0 0 0
& & &) ) )5 5 5/ / / $' ! ! ! !F  
$ $ $A A AQ/ Q/ Q/ Q/h3 3 3! ! !  F &&0F F F F*2 2 2' ' '* * *9 9 9? ? ?4 4 4= = =8 8 8	H 	H 	H5 5 5	& 	& 	&# # #
. . .
4 4 42 2 2
- - -( ( (  3 3 33 3 33 3 3E E EL L L$ $ $# # #
   %  
6 6 64 4 4$ $ $ $ $r   r   )rF   r,   r   rt  ra  op_utilr   r   r   	node_utilr   string_reprr   source_reprr	   r   r#   r$   r%   r(   r&   objectr*   r   r'   r   r   <module>r     sJ   $ 


   



 A A A A A A A A A A * * * * * * & & & & & & & & & & & & !(e)%)$+ $+ $+ $+N '5F!+$   . #"$$,( ,( ,( ,( ,(f ,( ,( ,(^v$ v$ v$ v$ v$) v$ v$ v$ v$ v$r   