
    Fe                       U d Z ddlmZ ddlZddlmZ i ej                  dej                  dej                  dej                  dej                  d	ej                  d
ej                  dej                  dej                  dej                  dej                   dej"                  dej$                  dej&                  dej(                  dej*                  dej,                  dej.                  dej0                  diZded<   eddd       Zeddd       Zdd dZ G d dej8                        Zy)!z'Helpers for AST (Abstract Syntax Tree).    )annotationsN)overload+and&|^/z//~z<<@*%not**orz>>-zdict[type[ast.AST], str]	OPERATORSc                     y N nodecodes     3/usr/lib/python3/dist-packages/sphinx/pycode/ast.pyunparser              c                     y r   r   r   s     r   r   r   $   r   r   c                `    | yt        | t              r| S t        |      j                  |       S )zUnparse an AST to string.N)
isinstancestr_UnparseVisitorvisitr   s     r   r   r   )   s/    |	D#	4 &&t,,r   c                      e Zd ZdddZddZeD ]  Ze e       dej                    <    ddZddZ	ddZ
ddZddZdd	Zdd
Zd dZd!dZd"dZd#dZd$dZd%dZd&dZd'dZd(dZd Zy))r"   c                    || _         y r   )r   )selfr   s     r   __init__z_UnparseVisitor.__init__4   s	    	r   c                (    t         |j                     S r   )r   	__class__r&   r   s     r   	_visit_opz_UnparseVisitor._visit_op7   s    ((r   visit_c                    |j                   r*|j                   d| j                  |j                          S |j                  S )N: )
annotationargr#   r*   s     r   	visit_argz_UnparseVisitor.visit_arg<   s5    ??hhZr$**T__"=!>??88Or   c                    | j                  |      }|r<|j                  r|d| j                  |      z  z  }|S |d| j                  |      z  z  }|S )z&Unparse a single argument to a string.z = %sz=%s)r#   r/   )r&   r0   defaultnames       r   _visit_arg_with_defaultz'_UnparseVisitor._visit_arg_with_defaultB   sW    zz#~~$**W"555  

7 333r   c           	        t        |j                        }t        |j                        }t        |j                        }||z  }t        t        |      |      D ]  }|j                  dd         t        |j                        }t        t        |      t        |j                              D ]  }|j                  dd         g }t        |j                        D ])  \  }}	|j                  | j                  |	||                + |j                  r|j                  d       t        |j                        D ],  \  }}	|j                  | j                  |	|||z                   . |j                  r-|j                  d| j                  |j                        z          |j                  r|j                  s|j                  d       t        |j                        D ])  \  }}	|j                  | j                  |	||                + |j                  r-|j                  d| j                  |j                        z          dj                  |      S )Nr   r
   r   r   , )listdefaultslenargsposonlyargsrangeinsertkw_defaults
kwonlyargs	enumerateappendr5   varargr#   kwargjoin)
r&   r   r9   positionalsr<   _r?   r;   ir0   s
             r   visit_argumentsz_UnparseVisitor.visit_argumentsL   s   *.t}}*=$))n$**+{"s8}k2 	%AOOAt$	% .2$2B2B-Cs;'T__)=> 	(Aq$'	(  0 01 	HFAsKK44S(1+FG	H KK		* 	VFAsKK44S(1{?:STU	V ;;KKdjj556??4;;KK0 	KFAsKK44S+a.IJ	K ::KKtzz$**556yyr   c                V    | j                  |j                         d|j                   S )N.)r#   valueattrr*   s     r   visit_Attributez_UnparseVisitor.visit_Attributeo   s%    **TZZ()499+66r   c                N    t        |j                  t        j                        rFdj	                  t         j                  |j                  |j                  |j                  f            S dj	                   fd|j                  |j                  |j                  fD              S )N  c              3  @   K   | ]  }j                  |        y wr   r#   .0er&   s     r   	<genexpr>z._UnparseVisitor.visit_BinOp.<locals>.<genexpr>v   s     P!

1P   )	r    opastPowrE   mapr#   leftrightr*   s   ` r   visit_BinOpz_UnparseVisitor.visit_BinOpr   sj    dggsww'773tzzDIItww

+KLMMxxP		477DJJ/OPPPr   c                     d j                  |j                        z  }|j                   fd|j                  D              S )Nz %s c              3  @   K   | ]  }j                  |        y wr   rS   rT   s     r   rW   z/_UnparseVisitor.visit_BoolOp.<locals>.<genexpr>z   s     :tzz!}:rX   )r#   rY   rE   values)r&   r   rY   s   `  r   visit_BoolOpz_UnparseVisitor.visit_BoolOpx   s3    djj))ww:dkk:::r   c                N   dj                  |j                  D cg c]  }| j                  |       c}|j                  D cg c],  }|j                   d| j                  |j
                         . c}z         }| j                  |j                         d| dS c c}w c c}w )Nr7   =())rE   r;   r#   keywordsr0   rL   func)r&   r   rV   kr;   s        r   
visit_Callz_UnparseVisitor.visit_Call|   s    yy;A$**Q-;FJmmTquugQtzz!''':&;<TU V**TYY'($q11 <Ts   B1B"
c                L   |j                   t        u ryt        |j                   t        t        t
        f      rX| j                  r7t        j                  | j                  |      xs t        |j                         S t        |j                         S t        |j                         S )Nz...)
rL   Ellipsisr    intfloatcomplexr   rZ   get_source_segmentreprr*   s     r   visit_Constantz_UnparseVisitor.visit_Constant   sp    ::!

S%$9:yy--dii>R$tzzBRRDJJ''

##r   c                      fd|j                   D        } fd|j                  D        }d t        ||      D        }ddj                  |      z   dz   S )Nc              3  F   K   | ]  }|j                  |        y wr   rS   )rU   rj   r&   s     r   rW   z-_UnparseVisitor.visit_Dict.<locals>.<genexpr>   s     B!AM

1Bs   !!c              3  @   K   | ]  }j                  |        y wr   rS   )rU   vr&   s     r   rW   z-_UnparseVisitor.visit_Dict.<locals>.<genexpr>   s     5A$**Q-5rX   c              3  2   K   | ]  \  }}|d z   |z     yw)r.   Nr   )rU   rj   rw   s      r   rW   z-_UnparseVisitor.visit_Dict.<locals>.<genexpr>   s     <$!QTA<s   {r7   })keysrb   ziprE   )r&   r   r{   rb   itemss   `    r   
visit_Dictz_UnparseVisitor.visit_Dict   sI    BtyyB55<#dF*;<TYYu%%++r   c                >    d| j                  |j                        z  S )Nzlambda %s: ...)r#   r;   r*   s     r   visit_Lambdaz_UnparseVisitor.visit_Lambda   s    $**TYY"777r   c                X     ddj                   fd|j                  D              z   dz   S )N[r7   c              3  @   K   | ]  }j                  |        y wr   rS   rT   s     r   rW   z-_UnparseVisitor.visit_List.<locals>.<genexpr>        @tzz!}@rX   ]rE   eltsr*   s   ` r   
visit_Listz_UnparseVisitor.visit_List   &    TYY@dii@@@3FFr   c                    |j                   S r   )idr*   s     r   
visit_Namez_UnparseVisitor.visit_Name   s    wwr   c                X     ddj                   fd|j                  D              z   dz   S )Nry   r7   c              3  @   K   | ]  }j                  |        y wr   rS   rT   s     r   rW   z,_UnparseVisitor.visit_Set.<locals>.<genexpr>   r   rX   rz   r   r*   s   ` r   	visit_Setz_UnparseVisitor.visit_Set   r   r   c                B    dd} ||j                         rOdj                   fd|j                   j                  D              } j                  |j                         d| dS  j                  |j                         d j                  |j                          dS )Nc                    t        | t        j                        xr4 t        | j                        xr t        d | j                  D               S )Nc              3  P   K   | ]  }t        |t        j                           y wr   )r    rZ   Starred)rU   elts     r   rW   zK_UnparseVisitor.visit_Subscript.<locals>.is_simple_tuple.<locals>.<genexpr>   s     OSJsCKK8Os   $&)r    rZ   Tupleboolr   any)rL   s    r   is_simple_tuplez8_UnparseVisitor.visit_Subscript.<locals>.is_simple_tuple   sB    5#)), P$POEJJOOOr   r7   c              3  @   K   | ]  }j                  |        y wr   rS   rT   s     r   rW   z2_UnparseVisitor.visit_Subscript.<locals>.<genexpr>   s!      7!" "ZZ] 7rX   r   r   )rL   zast.exprreturnr   )slicerE   r   r#   rL   )r&   r   r   r   s   `   r   visit_Subscriptz_UnparseVisitor.visit_Subscript   s    	 4::&99 7&*jjoo7 7Djj,-QtfA66**TZZ()4::djj+A*B!DDr   c                ,   t        |j                  t        j                        r9| j	                  |j                         d| j	                  |j
                         S | j	                  |j                         | j	                  |j
                         S )NrQ   )r    rY   rZ   Notr#   operandr*   s     r   visit_UnaryOpz_UnparseVisitor.visit_UnaryOp   sn     dggsww'jj)*!DJJt||,D+EFF**TWW%&tzz$,,'?&@AAr   c                     t        |j                        dk(  ryt        |j                        dk(  r!d j                  |j                  d         z  S ddj                   fd|j                  D              z   dz   S )	Nr   z()   z(%s,)rf   r7   c              3  @   K   | ]  }j                  |        y wr   rS   rT   s     r   rW   z._UnparseVisitor.visit_Tuple.<locals>.<genexpr>   s     "DQ4::a="DrX   rg   )r:   r   r#   rE   r*   s   ` r   visit_Tuplez_UnparseVisitor.visit_Tuple   se    tyy>Q^q TZZ		!555"D$))"DDDsJJr   c                D    t        dt        |      j                  z        )NzUnable to parse %s object)NotImplementedErrortype__name__r*   s     r   generic_visitz_UnparseVisitor.generic_visit   s    !"=T
@S@S"STTr   NrP   )r   r!   r   None)r   ast.ASTr   r!   )r   ast.argr   r!   )r0   r   r3   ast.AST | Noner   r!   )r   zast.argumentsr   r!   )r   zast.Attributer   r!   )r   z	ast.BinOpr   r!   )r   z
ast.BoolOpr   r!   )r   zast.Callr   r!   )r   zast.Constantr   r!   )r   zast.Dictr   r!   )r   z
ast.Lambdar   r!   )r   zast.Listr   r!   )r   zast.Namer   r!   )r   zast.Setr   r!   )r   zast.Subscriptr   r!   )r   zast.UnaryOpr   r!   )r   z	ast.Tupler   r!   )r   
__module____qualname__r'   r+   r   _oplocalsr1   r5   rI   rN   r_   rc   rk   rs   r~   r   r   r   r   r   r   r   r   r   r   r   r"   r"   3   s    ) 6,56#,,()6!F7Q;2
	$,8GGEBKUr   r"   r   )r   r   r   r!   r   r   )r   r   r   r!   r   r!   )r   r   r   r!   r   z
str | None)__doc__
__future__r   rZ   typingr   AddAndBitAndBitOrBitXorDivFloorDivInvertLShiftMatMultMultModr   r[   OrRShiftSubUAddUSubr   __annotations__r   NodeVisitorr"   r   r   r   <module>r      s   - " 
 'GGS'GGU' JJ' IIs	'
 JJ' GGS' LL$' JJ' JJ' KK' HHc' GGS' GGU' GGT' FFD'  JJ!'" GGS#'$ HHcHHc''	# . 
 
 
 
-IUcoo IUr   