
    1Vhs                     b   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlZddlmZ ddlmZ dd	lmZ dd
lmZ 	 	 ddZej*                  d        Zd Zd Zd Zd Zd Zd Zd Z G d dej<                        Z G d de       Z! G d de      Z"d Z#d Z$d Z%y)zBAnnotate python syntax trees with formatting from the source file.    )absolute_import)division)print_functionN)zip)ast_constants)	ast_utils)
formatting)token_generatorc           	      ^     t        j                          fd       }|S )Nc                    r| j                  |d      n	t               5  r!| j                  |
r| j                  nd        | |g|i | r| j	                  |	
rdnd       d d d        y # 1 sw Y   y xY w)NFtrailing_comma default
)	max_lines	semicoloncommentr   )scope_noop_contextprefix_indentsuffix)selfnodeargskwargsr   fmax_suffix_linesr   r   r   	statementr   s       C/home/dcms/DCMS/lib/python3.12/site-packages/pasta/base/annotate.pywrappedz_gen_wrapper.<locals>.wrapped*   s    49$**T%*
0} H	D)$,,Dd$T$V$	D$4	#YTB 	 	HH H Hs   AA77B 
contextlibwraps)	r   r   r   r   r    r   r   r!   r#   s	   ```````` r"   _gen_wrapperr'   (   s/    AH H H 
.    c               #      K   d  y wN r+   r(   r"   r   r   6   s	     s   c                     t        | d      S )z5Decorates a function where the node is an expression.r   )r    r'   r   s    r"   
expressionr/   ;   s    	a!	,,r(   c                     t        | d      S )zFDecorates a function where the node is a FormattedValue in an fstring.Fr   r-   r.   s    r"   fstring_expressionr2   @       	au	%%r(   c                     t        | d      S )zEDecorates a function where the node has whitespace prefix and suffix.Fr1   r-   r.   s    r"   space_aroundr5   E   r3   r(   c                     t        | dd      S )z:Decorates a function where the node has whitespace prefix.F)r   r   r-   r.   s    r"   
space_leftr7   J   s    	auU	33r(   c                 $    t        | ddddd      S )z3Decorates a function where the node is a statement.F   T)r   r    r   r   r!   r-   r.   s    r"   r!   r!   O   s    	auqD"d
4 4r(   c                     t        | dd      S )z&Special decorator for the module node.FT)r   r   r-   r.   s    r"   moduler;   U   s    	aud	33r(   c                 B     t        j                          fd       }|S )zADecorates a function where the node is a statement with children.c                 z   | j                  || j                          | |g|i | t        | d      rqt        j                  |      }|rY|j
                  t        |dd      k7  r>t        j                  |d      xs dj                         d   }| j                  ||       y y y | j                  |d	       y )
Nr   block_suffixlinenor   r   r   Tr   )r   r   hasattrr   get_last_childr?   getattrfmtget
splitlinesr>   r   )r   r   r   r   
last_childindentr   s         r"   r#   z block_statement.<locals>.wrapped\   s    KKdllK+dD"4"6"t^$++D1j	
))WT8Q-GG''*h/74CCEbI$' H kk$k%r(   r$   )r   r#   s   ` r"   block_statementrJ   Z   s'    A
& 
& 
.r(   c                       e Zd ZdZej
                  Zd Z fdZdvdZ		 	 dwdZ
d Zd Zej                  dxd       Zd	 Zdyd
ZdzdZd Zd Zd{dZd Zed        Zed        Zej6                  d        Zed        Zed        Zd Zed        Z d Z!ej6                  d        Z"ej6                  d        Z#d Z$e%d        Z&ed        Z'ed        Z(d Z)ed        Z*ed         Z+ed!        Z,ed"        Z-e.d#        Z/d$ Z0e.d%        Z1e.d&        Z2e.d'        Z3e.d(        Z4e5d)        Z6e.d*        Z7e.d+        Z8e.d,        Z9e.d-        Z:e.d.        Z;e.d/        Z<e.d0        Z=e.d1        Z>e5d2        Z?e.d3        Z@e.d4        ZAe.d5        ZBe.d6        ZCe5d7        ZDe5d8        ZEe5d9        ZFe5d:        ZGe5d;        ZHe5d<        ZId= ZJd> ZKd? ZLe5d@        ZMe5dA        ZNe5dB        ZOe5dC        ZPe5dD        ZQe5dE        ZRe5dF        ZSe5dG        ZTdydHZUe5dI        ZVe5dJ        ZWe5dK        ZXe5dL        ZYe5dM        ZZe5dN        Z[e5dO        Z\e5dP        Z]e%dQ        Z^dR Z_dS Z`dT ZadU ZbdV ZcdW ZddX ZedY ZfdZ Zgd[ Zhd\ Zid] Zjd^ Zkd_ Zld` Zmda Zndb Zodc Zpdd Zqde Zrdf Zsdg Ztdh Zudi Zvdj Zwdk Zxdl Zye%dm        Zze%dn        Z{e%do        Z|e%dp        Z}e~dq        Ze~dr        Ze~ds        Zdt Zedu        Z xZS )|BaseVisitora  Walks a syntax tree in the order it appears in code.

  This class has a dual-purpose. It is implemented (in this file) for annotating
  an AST with formatting information needed to reconstruct the source code, but
  it also is implemented in pasta.base.codegen to reconstruct the source code.

  Each visit method in this class specifies the order in which both child nodes
  and syntax tokens appear, plus where to account for whitespace, commas,
  parentheses, etc.
  c                 <    g | _         d| _        d| _        d| _        y )Nr   z  )_stackr   _indent_diff_default_indent_diffr   s    r"   __init__zBaseVisitor.__init__}   s     DKDLD $Dr(   c                     | j                   j                  |       t        t        |   |       || j                   j                         u sJ y r*   )rN   appendsuperrL   visitpop)r   r   	__class__s     r"   rV   zBaseVisitor.visit   s=    KKt	+t"4(4;;??$$$$r(   c                 8      j                  |d fdg|       y)z>Account for some amount of whitespace as the prefix to a node.r   c                  (     j                  d      S )NTrA   wsrQ   s   r"   <lambda>z$BaseVisitor.prefix.<locals>.<lambda>   s    twwtw'< r(   r   Nattr)r   r   r   s   `  r"   r   zBaseVisitor.prefix   s    IIdH<=wIOr(   c                 H      fd} j                  |d|g|       y)z>Account for some amount of whitespace as the suffix to a node.c                  ,    j                         S )N)r   r   r   r[   )r   r   r   r   s   r"   _wszBaseVisitor.suffix.<locals>._ws   s    WWyIwWOOr(   r   r   Nr^   )r   r   r   r   r   r   rb   s   ` ```  r"   r   zBaseVisitor.suffix   s    PIIdHseWI5r(   c              #   6  K   t        ||      }| j                  }| j                  }t        j                  |d   d      }|| j
                  }|| _        || j                  z   | _        |D ]  }|  | j                  |d|z  g        || _        || _        y w)Nr   indent_diffblock_suffix_%s)rD   r   rO   rE   rF   rP   r_   )r   r   children_attrchildrenprev_indentprev_indent_diffnew_diffchilds           r"   indentedzBaseVisitor.indented   s     t]+H,,K((wwx{M2H**h D!2!22DL kIId%5r:DL(Ds   BBc                     || _         y r*   )rP   )r   rI   s     r"   set_default_indent_diffz#BaseVisitor.set_default_indent_diff   s
     &Dr(   c              #      K   |r| j                  ||dz   g |rdnd       d |r| j                  ||dz   g |rdnd       yyw)aB  Context manager to handle a parenthesized scope.

    Arguments:
      node: (ast.AST) Node to store the scope prefix and suffix on.
      attr: (string, optional) Attribute of the node contained in the scope, if
        any. For example, as `None`, the scope would wrap the entire node, but
        as 'bases', the scope might wrap only the bases of a class.
      trailing_comma: (boolean) If True, allow a trailing comma at the end.
      default_parens: (boolean) If True and no formatting information is
        present, the scope would be assumed to be parenthesized.
    _prefix(r   r   N_suffix)r^   r   r   r_   r   default_parenss        r"   r   zBaseVisitor.scope   s\      
iidY&-2  7	
iidY&-2  7 s   AAc                      y)zAccount for a specific token.Nr+   )r   	token_vals     r"   tokenzBaseVisitor.token       r(   c                      y)z'Handles an attribute on the given node.Nr+   )r   r   	attr_name	attr_valsdepsr   s         r"   r_   zBaseVisitor.attr   ry   r(   c                      y)a9  Account for some amount of whitespace.

    Arguments:
      max_lines: (int) Maximum number of newlines to consider.
      semicolon: (boolean) If True, parse up to the next semicolon (if present).
      comment: (boolean) If True, look for a trailing comment even when not in
        a parenthesized scope.
    r   r+   )r   r   r   r   s       r"   r\   zBaseVisitor.ws   s     r(   c                     d|z  S )zAccount for a number of dots..r+   )r   num_dotss     r"   dotszBaseVisitor.dots   s    >r(   c                 &    | j                  d      S )z)Account for up to one line of whitespace.r9   r   r[   rQ   s    r"   
ws_onelinezBaseVisitor.ws_oneline   s    77Q7r(   c                      y)z/Account for a suffix that may or may not occur.Nr+   )r   r   r{   rw   r   s        r"   optional_tokenzBaseVisitor.optional_token   ry   r(   c                     |d   S )%Account for one of the given symbols.r   r+   )r   symbolss     r"   one_of_symbolszBaseVisitor.one_of_symbols   s    1:r(   c                 &    | j                  |       y r*   )generic_visitr   r   s     r"   visit_ModulezBaseVisitor.visit_Module   s    tr(   c                    t        j                  |d      rdnd}| j                  |d|| j                  g|dz          | j	                  |j
                         | j                  |d| j                  d| j                  gd	       | j                  |d
      D ]  }| j	                  |        |j                  r$t        |j                        dk(  rt        |j                  d   t        j                        ra| j                  |j                  d         rCt        j                  |j                  d   dd       | j	                  |j                  d          y | j                  |d| j                  g       | j                  d       | j                  |d| j                  d| j                  gd	       | j                  |d      D ]  }| j	                  |        y y )Nis_elifelififopen_if r   
open_block::
bodyr9   r   T
elseprefixelse	open_elseorelse)rE   rF   r_   r\   rV   testr   rl   r   len
isinstanceastIfcheck_is_elifsetrx   )r   r   tokstmts       r"   visit_IfzBaseVisitor.visit_If   s~   GGD),&$CIIdITWW~sSyIAJJtyyIIdL477C"A   dF+ 
jj {{
dkk
a
Jt{{1~svv$F


T[[^
,A	40

4;;q>"		$twwi0

6		$dggsDOO%D 	 	!MM$1 	D
**T
	 r(   c                      y)a  Return True if the node continues a previous `if` statement as `elif`.

    In python 2.x, `elif` statments get parsed as If nodes. E.g, the following
    two syntax forms are indistinguishable in the ast in python 2.

    if a:
      do_something()
    elif b:
      do_something_else()

    if a:
      do_something()
    else:
      if b:
        do_something_else()

    This method should return True for the 'if b' node if it has the first form.
    Nr+   r   s     r"   r   zBaseVisitor.check_is_elif   ry   r(   c           	         | j                  |dd| j                  gd       | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |d      D ]  }| j                  |        |j                  rn| j                  |d	| j                  d	| j                  d| j                  g| j                  d
z          | j                  |d      D ]  }| j                  |        y y )Nwhile_keywordwhilezwhile r   r   r   r   r   r   else:
r   )r_   r\   rV   r   r   rl   r   r   r   r   r   s      r"   visit_WhilezBaseVisitor.visit_While  s    IIdOgtww%7IJJJtyyIIdL477C"A  dF+ 
jj {{
iiftwwdooNy0  2--h/ $

4 r(   c           	      V   t        t        d      rHt        |t        j                        r.| j	                  |dd| j
                  d| j
                  gd       n!| j	                  |dd| j
                  gd       | j                  |j                         | j	                  |d| j
                  d	| j
                  gd
       | j                  |j                         | j	                  |d| j
                  d| j                  gd       | j                  |d      D ]  }| j                  |        |j                  rn| j	                  |d| j
                  d| j
                  d| j                  g| j                  dz          | j                  |d      D ]  }| j                  |        y y )NAsyncForfor_keywordasyncforz
async for r   zfor for_inin in r   r   r   r   r   r   r   )rB   r   r   r   r_   r\   rV   targetiterr   rl   r   r   r   s      r"   	visit_ForzBaseVisitor.visit_For  se   sJJtS\\$B
iimgtwwtww%G$  & iimeTWW%5viFJJt{{IIdHtwwdgg6IGJJtyyIIdL477C"A  dF+ 

4 {{
iiftwwdooNy0  2 --h/ $

4	 r(   c                 $    | j                  |      S r*   )r   r   s     r"   visit_AsyncForzBaseVisitor.visit_AsyncFor5  s    >>$r(   c                    t        |d      r| j                  |      S t        |dd      s!| j                  |dd| j                  gd       | j                  |j                         |j                  rG| j                  |d| j                  d| j                  gd	       | j                  |j                         t        |j                        d
k(  r_| j                  |j                  d         rAd|j                  d   _        | j                  |d| j                  d| j                  gd       n,| j                  |d| j                  d| j                  gd       | j                  |d      D ]  }| j                  |        y )Nitemsis_continuedFwithwith r   with_asas as r9   r   T
with_comma,, r   r   r   r   )rB   visit_With_3rD   r_   r\   rV   context_exproptional_varsr   r   check_is_continued_withr   r   rl   r   s      r"   
visit_WithzBaseVisitor.visit_With8  s=   tWt$$4/
iifvtww/iAJJt  !
iii$''4!96iJ
jj##$
499~t;;DIIaLI"&diil
iilTWWc477$;TiJ
iilTWWc4??$C  dF+ 
jjr(   c                 $    | j                  |      S r*   )r   r   s     r"   visit_AsyncWithzBaseVisitor.visit_AsyncWithL  s    ??4  r(   c                      y r*   r+   r   s     r"   check_is_continued_tryz"BaseVisitor.check_is_continued_tryO  s    r(   c                      y)a  Return True if the node continues a previous `with` statement.

    In python 2.x, `with` statments with many context expressions get parsed as
    a tree of With nodes. E.g, the following two syntax forms are
    indistinguishable in the ast in python 2.

    with a, b, c:
      do_something()

    with a:
      with b:
        with c:
          do_something()

    This method should return True for the `with b` and `with c` nodes.
    Nr+   r   s     r"   r   z#BaseVisitor.check_is_continued_withS  ry   r(   c                 >   t        t        d      rHt        |t        j                        r.| j	                  |dd| j
                  d| j
                  gd       n!| j	                  |dd| j
                  gd       t        |j                        D ]C  \  }}| j                  |       |t        |j                        dz
  k7  s3| j                  d       E | j	                  |d	d
| j                  gd       | j                  |d      D ]  }| j                  |        y )N	AsyncWithr   r   zasync with r   r   r9   r   with_body_openr   r   r   )rB   r   r   r   r_   r\   	enumerater   rV   r   rx   r   rl   )r   r   iwithitemr   s        r"   r   zBaseVisitor.visit_With_3f  s    sK Zcmm%D
iifwA%  ' iifvtww/iA , 8
jj	
c$**o!	!

3
 	IId$sDOO&<eILdF+ 
jjr(   c                     | j                  |j                         |j                  rH| j                  |d| j                  d| j                  gd       | j                  |j                         y y )Nr   r   r   )rV   r   r   r_   r\   r   s     r"   visit_withitemzBaseVisitor.visit_withitemv  sW    JJt  !
iidTWWdDGG4fiE
jj##$ r(   c                    t        |j                        D ]j  \  }}| j                  |d|z  | j                  dgd       | j	                  |       | j                  |d|z  | j                  gd| j
                  z          l | j                  |dd| j                  |j                  | j                  gd|j                  z  d	
       t        |dg       t        |dg       z   }| j                  |dt        |      d      5  t        |j                        D ]d  \  }}| j	                  |       | j                  |d|z  | j                  g       ||d   k7  sA| j                  |d|z  d| j                  gd       f t        |d      rt        |j                        D ]n  \  }}| j	                  |       | j                  |d|z  | j                  g       ||j                  d   k7  sK| j                  |d|z  d| j                  gd       p d d d        | j                  |d| j                  d| j                  gd       | j                  |d      D ]  }| j	                  |        y # 1 sw Y   ^xY w)Nzdecorator_prefix_%d@r   decorator_suffix_%dr   	class_defclasszclass %snamer   r}   baseskeywordsTr   ru   zbase_suffix_%dr@   zbase_sep_%dr   r   zkeyword_suffix_%dzkeyword_sep_%dr   r   r   r   )r   decorator_listr_   r\   rV   r   r   rD   r   boolr   rB   r   r   rl   )r   r   r   	decorator
class_argsbasekeywordr   s           r"   visit_ClassDefzBaseVisitor.visit_ClassDef}  sV   !$"5"56 -9
ii+a/$''3iM
jj
ii+a/$''t||+  --
 	IIdK'477DIItww!G 499,9  >w+gdJ.KKJ	D'$z2B#' 
 
) Ptzz* K'!T

4		$(1,twwi8:b>!
))D-!+c477^T)
J	K
 
z	"#DMM2 	PJAw
**W

))D-1DGG9
=b))IId,q03.$IO		PP 	IIdL477C"A  dF+ 
jjP Ps   AI-BI-*&I--I6c                    t        |j                        D ]u  \  }}| j                  |d|z  | j                  d| j                  gd       | j	                  |       | j                  |d|z  | j
                  gd| j                  z          w t        t        d      rwt        |t        j                        r]| j                  |d| j                  d| j                  d	| j                  |j                  | j                  gd
d|j                  z         nP| j                  |d| j                  d	| j                  |j                  | j                  gd
d|j                  z         t        |j                  dg       }t        t        |j                  j                  |z         |j                  j                   rdnd|j                  j"                  rdndf      }| j%                  |d|dkD  d      5  | j	                  |j                         d d d        t        |dd       rH| j                  |d| j                  d| j                  gdd       | j	                  |j&                         | j                  |d| j                  d| j
                  gd       | j)                  |d      D ]  }| j	                  |        y # 1 sw Y   xY w)Nzdecorator_symbol_%dr   r   r   r   AsyncFunctionDeffunction_defr   defr   zasync def %sr}   r   zdef %s
kwonlyargsr9   r   r   Tr   returnsreturns_prefixz->)r   z -> r   r   r   r   )r   r   r_   r\   rV   r   r   rB   r   r   r   r   rD   r   sumr   varargkwargr   r   rl   )r   r   r   r   r   
args_countr   s          r"   visit_FunctionDefzBaseVisitor.visit_FunctionDef  sj   !$"5"56 -9
ii+a/$''31H  
jj
ii+a/$//1Bt||+  -	- 	'(4--.
iin'477E477DIItwwO(B  D iin%$))TWW=499(<  > L"5Jc$))..:5699++a99??a3 4J 
D&a#' 
 
) 
jj tY%
ii&$(@!6  3
jjIIdL477C"A  dF+ 
jj s   2K  K	c                 $    | j                  |      S r*   )r   r   s     r"   visit_AsyncFunctionDefz"BaseVisitor.visit_AsyncFunctionDef  s    !!$''r(   c           	      @   | j                  |dd| j                  d| j                  gd       t        |j                        dk(  rQ| j                  |j                  d         r3d|j                  d   _        | j                  |j                  d          n(| j                  |d	      D ]  }| j                  |        | j                  |d
| j                  d| j                  d| j                  gd       | j                  |d      D ]  }| j                  |        y )Nopen_trytryr   try:
r   r9   r   Tr   open_finallyfinally	finally:
	finalbody)	r_   r\   r   r   r   r   r   rV   rl   r   s      r"   visit_TryFinallyzBaseVisitor.visit_TryFinally  s     	IIdJdoo F    499~t::499Q<H"&diil
jj1--f- $

4IIdNww	477CA"  $ dK0 
jjr(   c           	         t        |dd      s-| j                  |dd| j                  d| j                  gd       | j	                  |d      D ]  }| j                  |        |j                  D ]  }| j                  |        |j                  ra| j                  |d	| j                  d
| j                  d| j                  gd       | j	                  |d      D ]  }| j                  |        y y )Nr   Fr   r   r   r   r   r   r   r   r   r   )rD   r_   r\   r   rl   rV   handlersr   r   r   r   handlers       r"   visit_TryExceptzBaseVisitor.visit_TryExcept  s    4/
iij5$''3"H   "dF+ 
jj== 
jj{{
iik&$''3@!  # --h/ $

4	 r(   c           	         | j                  |d| j                  d| j                  d| j                  gd       | j                  |d      D ]  }| j	                  |        |j
                  D ]  }| j	                  |        |j                  r`| j                  |d| j                  d| j                  d| j                  gd	       | j                  |d
      D ]  }| j	                  |        |j                  ra| j                  |d| j                  d| j                  d| j                  gd       | j                  |d      D ]  }| j	                  |        y y )Nr   r   r   r   r   r   r   r   r   r   r   r   r   r  )r_   r\   r   rl   rV   r  r   r  r  s       r"   	visit_TryzBaseVisitor.visit_Try  sA    	IIdJ%#t O   dF+ 
jj== 
jj{{
iik&$''3@!  # --h/ $

4~~
iin)TWWc4??C$  & --k2 $

4	 r(   c           	         | j                  d       |j                  r| j                  |j                         |j                  rH|j                  r<| j	                  |d| j
                  | j                  dd      | j
                  gd       |j                  r[t        |j                  t        j                        r| j                  |j                         n| j                  |j                         | j	                  |d| j
                  d| j                  gd       | j                  |d	      D ]  }| j                  |        y )
Nexceptr   r   r   r   r   r   r   r   )rx   typerV   r   r_   r\   r   r   r   ASTr   rl   r   s      r"   visit_ExceptHandlerzBaseVisitor.visit_ExceptHandler  s    JJxyy
jjyyTYY
iidTWWd&9&9$&DdggN   yy	DIIsww	'

499

499IIdL477C"A  dF+ 
jjr(   c                 <   t        |d      r| j                  |      S | j                  d       |j                  r;| j	                  |d| j
                  gd       | j                  |j                         |j                  rG| j	                  |d| j
                  d| j
                  gd       | j                  |j                         |j                  rH| j	                  |d	| j
                  d| j
                  gd       | j                  |j                         y y )
Ncauseraisetype_prefixr   r   inst_prefixr   r   tback_prefix)	rB   visit_Raise_3rx   r  r_   r\   rV   insttbackr   s     r"   visit_RaisezBaseVisitor.visit_Raise  s    tW%%JJwyy
iimdggYi<
jjyy
iimdggsDGG%<diK
jjzz
iintwwTWW&=tiL
jj r(   c                 `   |j                   r| j                  |dd| j                  gd       | j                  |j                          |j                  rH| j                  |d| j                  d| j                  gd       | j                  |j                         y y | j                  d       y )N
open_raiser  zraise r   cause_prefixfromz from )excr_   r\   rV   r  rx   r   s     r"   r  zBaseVisitor.visit_Raise_3  s    xx
iilWdgg$6iI
jj			$&$''(B" 	 	$

4:: 

 jjr(   c                    | j                  |dd| j                  gd       | j                  |j                         |j                  r=| j                  |dd| j                  gd       | j                  |j                         y y )Nassert_openassertzassert r   
msg_prefixr   r   )r_   r\   rV   r   msgr   s     r"   visit_AssertzBaseVisitor.visit_Assert*  sg    IIdMHdgg#6	IJJJtyyxx
iilS$''NDiA
jj r(   c                     t        |j                        D ]E  \  }}| j                  |       | j                  |d|z  | j                  d| j                  gd       G | j                  |j
                         y )Nzequal_%d= = r   )r   targetsrV   r_   r\   valuer   r   r   r   s       r"   visit_AssignzBaseVisitor.visit_Assign2  se    t||, N	6
jj
iij1ntwwTWW&=uiMN 	JJtzzr(   c                 &   | j                  |j                         dt        j                  t	        |j
                           d   z  }| j                  |d| j                  || j                  gd|z         | j                  |j                         y )Nz%s=r   operator %s r   )	rV   r   r   NODE_TYPE_TO_TOKENSr  opr_   r\   r(  )r   r   op_tokens      r"   visit_AugAssignzBaseVisitor.visit_AugAssign9  sr    JJt{{}88dggGJJHIIdJ(DGG <x'  )JJtzzr(   c                 p   | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |j                         |j
                  rH| j                  |d| j                  d| j                  gd       | j                  |j
                         y y )Ncolonr   : r   equalr%  r&  )rV   r   r_   r\   
annotationr(  r   s     r"   visit_AnnAssignzBaseVisitor.visit_AnnAssignA  s     	JJt{{IIdGdggsDGG4dICJJtzz
iigdgg6iF
jj r(   c                 |    | j                  |dd| j                  gd       | j                  |j                         y )Nawaitzawait r   r_   r\   rV   r(  r   s     r"   visit_AwaitzBaseVisitor.visit_AwaitK  s/    IIdGgtww/IBJJtzzr(   c                 &    | j                  d       y )Nbreakrx   r   s     r"   visit_BreakzBaseVisitor.visit_BreakP  s    JJwr(   c                 &    | j                  d       y )Ncontinuer>  r   s     r"   visit_ContinuezBaseVisitor.visit_ContinueT  s    JJzr(   c                 $   | j                  |dd| j                  gd       t        |j                        D ]W  \  }}| j	                  |       ||j                  d   us)| j                  |d|z  | j                  d| j                  gd       Y y )Ndelzdel r   r@   comma_%dr   r   )r_   r\   r   r'  rV   r)  s       r"   visit_DeletezBaseVisitor.visit_DeleteX  s    IIdEE477+VI<t||, O	6
jj	t||B'	'		$
Q#tww(?	NOr(   c           
      <   | j                  |dd| j                  gd       | j                  |ddd      5  | j                  |j                         |j
                  r| j                  |d| j                  | j                  dd	      | j                  gd
       | j                  |j
                         |j                  rG| j                  |d| j                  d	| j                  gd
       | j                  |j                         d d d        y # 1 sw Y   y xY w)Nexecr   r   FTr   
in_globalsr   r   r   	in_locals)r_   r\   r   rV   r   globalsr   localsr   s     r"   
visit_ExeczBaseVisitor.visit_Exec`  s     	IIdFVTWW-vI>	D&t	L 	"
jj			$77D//c:DGGD 	 	  	

4<< ;;
))D+dgg'>)
M
**T[[
!	" 	" 	"s   CDDc                 :    | j                  |j                         y r*   rV   r(  r   s     r"   
visit_ExprzBaseVisitor.visit_Expro      JJtzzr(   c                 
   | j                  d       g }|j                  D ]N  }||j                  d   k7  r|j                  | j                  dg       |j                  | j                  |g       P | j	                  |d|       y )Nglobalr   r   namesrx   rT  extendr\   r_   r   r   identifiersidents       r"   visit_GlobalzBaseVisitor.visit_Globals  su    JJxK +	$**Q-	DGGS>*$''5)*+ 	IIdG[)r(   c                 6   | j                  d       t        |j                        D ]p  \  }}| j                  |d|z  | j                  gd       | j                  |       ||j                  d   k7  sM| j                  |d|z  | j                  dgd       r y )Nimportalias_prefix_%dr   r   r@   alias_sep_%dr   )rx   r   rT  r_   r\   rV   )r   r   r   aliass       r"   visit_ImportzBaseVisitor.visit_Import}  s    JJxdjj) I5
ii'!+dggYiD
jj	$**R.	 		$*TWWcNC	H	Ir(   c           	         | j                  d       | j                  |d| j                  gd       g }|j                  dkD  r6|j	                  | j                  |j                        | j                  g       |j                  rV|j                  j                  d      }|d d D ]  }|| j                  || j                  dgz  }! || j                  |d   gz  }| j                  |d|d	d|j                  z  |j                  xs d
z          | j                  |d| j                  gd       | j                  d       | j                  |dd      5  t        |j                        D ]o  \  }}| j                  |d|z  | j                  gd       | j                  |       ||j                  d   usL| j                  |d|z  | j                  dgd       q 	 d d d        y # 1 sw Y   y xY w)Nr  module_prefixr   r   r   r   r@   r;   )levelr;   r   r   module_suffixr\  rT  Tr   r]  r^  r   )rx   r_   r\   rc  rV  r   r;   splitr   r   rT  rV   )r   r   module_patternpartspartr   r_  s          r"   visit_ImportFromzBaseVisitor.visit_ImportFrom  s   JJvIIdOdggYI<NzzA~TYYtzz2DGG<={{kk$e* 8$477D$''3778%),,nIIdHn&DJJ&$++*;<  > 	IIdOdggYI<JJx	D'$	7 K

+ K(!U		$)A-y#	F

5

2&
))D.1,twwnc)
J	KK K Ks   A!G&6&G&&G/c                     | j                  t               | j                  |dt        z  | j                  d| j                  gd       | j                  |j
                         y )Nr5  z:=z := r   )rV   r   r_   r   r\   r(  r   s     r"   visit_NamedExprzBaseVisitor.visit_NamedExpr  sE    JJvIIdGaK$''4!96IJJJtzzr(   c                 
   | j                  d       g }|j                  D ]N  }||j                  d   k7  r|j                  | j                  dg       |j                  | j                  |g       P | j	                  |d|       y )Nnonlocalr   r   rT  rU  rW  s       r"   visit_NonlocalzBaseVisitor.visit_Nonlocal  su    JJzK +	$**Q-	DGGS>*$''5)*+ 	IIdG[)r(   c                 &    | j                  d       y )Npassr>  r   s     r"   
visit_PasszBaseVisitor.visit_Pass  s    JJvr(   c                    | j                  |dd| j                  gd       |j                  r| j                  |dd| j                  gd       | j                  |j                         |j                  r-| j                  |d| j                  d| j                  gd	       n-|j
                  s!| j                  |d
| j                  dgd       t        |j                        D ]  \  }}| j                  |       ||j                  d   ur0| j                  |d|z  | j                  d| j                  gd	       X|j
                  re| j                  |d
| j                  dgd        y )N
print_openprintzprint r   redirectionz>>values_prefixr   r   r   r@   rE  )r_   r\   destrV   valuesnlr   )r   r   r   r(  s       r"   visit_PrintzBaseVisitor.visit_Print  s%   IIdL7DGG"4hIGyy
iimdDGG_diC
jj			$$''3)@$	Oww		$(477C.#	Fdkk* G5
jj	dkk"o	%		$
Q#tww(?	Nww		$(477C.#	FGr(   c                     | j                  d       |j                  r<| j                  |d| j                  gd       | j	                  |j                         y y )Nreturnreturn_value_prefixr   r   rx   r(  r_   r\   rV   r   s     r"   visit_ReturnzBaseVisitor.visit_Return  sE    JJxzz
ii+dggYiD
jj r(   c                     | j                  d       |j                  r<| j                  |d| j                  gd       | j	                  |j                         y y )Nyieldyield_value_prefixr   r   r~  r   s     r"   visit_YieldzBaseVisitor.visit_Yield  sE    JJwzz
ii*TWWIsiC
jj r(   c                     | j                  |dd| j                  d| j                  gd       | j                  |j                         y )N
yield_fromr  r  zyield from r   r:  r   s     r"   visit_YieldFromzBaseVisitor.visit_YieldFrom  s=    IIdL7DGGVTWW"E#  %JJtzzr(   c                     | j                  |j                         | j                  |d| j                  d| j                  gd       | j	                  |j                         y )Ndotr   r   )rV   r(  r_   r\   rx   r   s     r"   visit_AttributezBaseVisitor.visit_Attribute  sE    JJtzzIIdEDGGS$''2CI@JJtyyr(   c                 "   t         j                  t        |j                           d   }| j	                  |j
                         | j                  |d| j                  || j                  gd|z  d       | j	                  |j                         y )Nr   r/  r-  r/  r   )	r   r.  r  r/  rV   leftr_   r\   rightr   r   	op_symbols      r"   visit_BinOpzBaseVisitor.visit_BinOp  so    11$tww-@CIJJtyyIIdD477Itww7y(w  8JJtzzr(   c                 <   t         j                  t        |j                           d   }t	        |j
                        D ][  \  }}| j                  |       ||j
                  d   us)| j                  |d|z  | j                  || j                  gd|z  d       ] y )Nr   r@   zop_%dr-  r  r   )	r   r.  r  r/  r   rx  rV   r_   r\   )r   r   r  r   r(  s        r"   visit_BoolOpzBaseVisitor.visit_BoolOp  s    11$tww-@CIdkk* <5
jj	dkk"o	%		$!dggy$''%B 9,7 	 	<<r(   c                 (   | j                  |j                         | j                  |dd      5  t        j                  d d dk\  r| j                  |      }n| j                  |      }|r| j                  |dd       d d d        y # 1 sw Y   y xY w)N	argumentsTru      )      r   r   )rV   funcr   sysversion_infovisit_Call_arguments35visit_Call_argumentsr   )r   r   any_argss      r"   
visit_CallzBaseVisitor.visit_Call  s    JJtyy	D+d	; 	9 
		"1		'..t4,,T2	D"2C8	9 	9 	9s   ABBc                    d }|j                   r8t        |j                  D cg c]  }d |f c}d|j                   fgz   |      }n|j                  D cg c]  }d |f }}|j                  D cg c]  }d |f c}|z   }|j                  r|j                  d|j                  f       t        |      D ]y  \  }\  }}	|$| j                  |d|z  | j                  |g|       | j                  |	       |	|d   d   usK| j                  |d	|z  | j                  d
| j                  gd       { t        |      S c c}w c c}w c c}w )Nc                     | d   }t        |t        j                        r|j                  }t	        |dd      t	        |dd      fS )Nr9   r?   r   
col_offsetr   r   r   r(  rD   )tupargs     r"   arg_locationz6BaseVisitor.visit_Call_arguments.<locals>.arg_location  s?    Fc	C	%iic8Q'lA)FGGr(   *key**z	%s_prefixr   r@   r9   rE  r   r   )starargssortedr   r   r   rT   r   r_   r\   rV   r   )
r   r   r  kwsorted_keywordsnall_argsr   r   r  s
             r"   r  z BaseVisitor.visit_Call_arguments  s=   H }} $
."D":
.32F1G
Go /3mm<$<o<#'99-aq	-?H{{ootT[[)*%h/ O=FC				$f,tww.?	P
jjo	HRLO	#		$
Q#tww(?	NO > / =-s   D=E1Ec                 B   d }t        |j                  |j                  z   t        j                  |            }t        |      D ]M  \  }}| j                  |       ||d   us| j                  |d|z  | j                  d| j                  gd       O t        |      S )Nc                     d } ||       rt        |t        j                        ry ||      rt        | t        j                        ryd } ||       } ||      }d|v sd|v ry||k  rdS ||k(  rdS dS )z&Old-style comparator for sorting args.c                 X    t        | t        j                  t        j                  f       S r*   )r   r   r   Starredas    r"   is_argzGBaseVisitor.visit_Call_arguments35.<locals>.arg_compare.<locals>.is_arg!  s    a#++s{{!;<<<r(   r@   r9   c                     t        | t        j                        r| j                  } t	        | dd       t	        | dd       fS )Nr?   r  r  r  s    r"   get_poszHBaseVisitor.visit_Call_arguments35.<locals>.arg_compare.<locals>.get_pos-  s6    a%gg!8T*GA|T,JKKr(   Nr   )r   r   r   )a1a2r  r  pos1pos2s         r"   arg_comparez7BaseVisitor.visit_Call_arguments35.<locals>.arg_compare  s    = 

2s{{3":*R5
L
 R[dR[d	 $;R<A<1<r(   r  r@   rE  r   r   r   )
r  r   r   	functools
cmp_to_keyr   rV   r_   r\   r   )r   r   r  r  r   r  s         r"   r  z"BaseVisitor.visit_Call_arguments35  s    => dii$--/#..{;=H H% O3
jjo	HRL	 		$
Q#tww(?	NO >r(   c                 |    | j                  |dd| j                  gd       | j                  |j                         y )Nstarr  r   r:  r   s     r"   visit_StarredzBaseVisitor.visit_StarredG  s.    IIdFS$''NCI8JJtzzr(   c                 r   | j                  |j                         t        t        |j                  |j
                              D ]p  \  }\  }}| j                  |d|z  | j                  gd       | j                  |       | j                  |d|z  | j                  gd       | j                  |       r y )Nzop_prefix_%dr   r   zop_suffix_%d)rV   r  r   r   opscomparatorsr_   r\   )r   r   r   r/  
comparators        r"   visit_ComparezBaseVisitor.visit_CompareK  s    JJtyy(TXXt7G7G)HI B

iinq(477)SiA
jjn
iinq(477)SiA
jj	r(   c                    | j                  d       t        t        t        |j                              |j                  |j
                        D ]  \  }}}|%| j                  |d|z  | j                  dgd       n@| j                  |       | j                  |d|z  | j                  d| j                  gd       | j                  |       ||j
                  d   us| j                  |d	|z  | j                  d
| j                  gd        | j                  |dd
d       | j                  |d| j                  dgd       y )N{zstarstar_%dr  r   zkey_val_sep_%dr   r4  r@   rE  r   r   
extracommaTallow_whitespace_prefixclose_prefix})
rx   r   ranger   keysrx  r_   r\   rV   r   )r   r   r   r  r(  s        r"   
visit_DictzBaseVisitor.visit_DictT  s   JJsOU3tyy>2DIIt{{K 
O3			$)DGGT?D	I

3		$(1,twwTWW.E 	 	 
jj	dkk"o	%		$
Q#tww(?	N
O 	lCNIIdNTWWcNCI@r(   c                    | j                  |dd| j                  gd       | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |j                         |j
                  D ]  }| j                  |        | j                  |d| j                  dgd       y )	N	open_dictr  r   key_val_sepr   r4  
close_dictr  )r_   r\   rV   r  r(  
generators)r   r   comps      r"   visit_DictCompzBaseVisitor.visit_DictCompe  s    IIdK#twwI=JJtxxIIdMDGGS$''#:DIIJJtzz 
jjIIdL477C.#I>r(   c                 &    | j                  |       y r*   	_comp_expr   s     r"   visit_GeneratorExpzBaseVisitor.visit_GeneratorExpo  s    NN4r(   c                 V   | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |j
                         y )Nr    if r   r   z else )rV   r   r_   r\   r   r   r   s     r"   visit_IfExpzBaseVisitor.visit_IfExps  sx    JJtyyIIdD477D$''2FICJJtyyIIdFTWWfdgg6IIJJt{{r(   c                 
   | j                  |dd| j                  gd       | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |j                         y )N
lambda_deflambdazlambda r   open_lambdar   r4  )r_   r\   rV   r   r   r   s     r"   visit_LambdazBaseVisitor.visit_Lambda{  sb    IIdL8TWW"5yIIJJtyyIIdMDGGS$''#:DIIJJtyyr(   c                    | j                  |dd| j                  gd       t        |j                        D ]W  \  }}| j	                  |       ||j                  d   us)| j                  |d|z  | j                  d| j                  gd       Y |j                  r| j                  |ddd	
       | j                  |d| j                  dgd       y )N	list_open[r   r@   rE  r   r   r  Tr  
list_close]r_   r\   r   eltsrV   r   r   r   r   elts       r"   
visit_ListzBaseVisitor.visit_List  s    IIdK#twwI=DII& O3
jjo	DIIbM	!		$
Q#tww(?	NO yy
$c4PIIdL477C.#I>r(   c                 ,    | j                  |dd       y )Nr  r  
open_braceclose_bracer  r   s     r"   visit_ListCompzBaseVisitor.visit_ListComp      NN4CSN9r(   c                 $   |r!| j                  |d|| j                  g|       | j                  |j                         t	        |j
                        D ]  \  }}| j                  |        |r"| j                  |d| j                  |g|       y y )Ncompexp_openr   compexp_close)r_   r\   rV   r  r   r  )r   r   r  r  r   r  s         r"   r  zBaseVisitor._comp_exp  s    
iinz477&;ZiPJJtxxT__- 4
jj
iio'=#  % r(   c                 :    | j                  |j                         y r*   )rx   idr   s     r"   
visit_NamezBaseVisitor.visit_Name  s    JJtwwr(   c                 L    | j                  t        |j                               y r*   )rx   strr(  r   s     r"   visit_NameConstantzBaseVisitor.visit_NameConstant  s    JJs4::r(   c                     | j                  |dd| j                  gd       | j                  |j                         | j                  |d| j                  dgd       y )N	repr_open`r   
repr_closer:  r   s     r"   
visit_ReprzBaseVisitor.visit_Repr  sJ    IIdK#twwI=JJtzzIIdL477C.#I>r(   c                    | j                  |dd| j                  gd       t        |j                        D ]l  \  }}| j	                  |       ||j                  d   ur0| j                  |d|z  | j                  d| j                  gd       X| j                  |ddd	
       n | j                  |d| j                  dgd       y )Nset_openr  r   r@   rE  r   r   r  Tr  	set_closer  r  r  s       r"   	visit_SetzBaseVisitor.visit_Set  s    IIdJdggI<DII& :3
jjo	DIIbM	!		$
Q#tww(?	ND,48 	 	:: 	IIdK$''3I=r(   c                 ,    | j                  |dd       y )Nr  r  r  r  r   s     r"   visit_SetCompzBaseVisitor.visit_SetComp  r  r(   c                 
   | j                  |j                         | j                  |d| j                  d| j                  gd       | j                  |j                         | j                  |d| j                  dgd       y )N
slice_openr  r   slice_closer  )rV   r(  r_   r\   slicer   s     r"   visit_SubscriptzBaseVisitor.visit_Subscript  sa    JJtzzIIdL477C"93IGJJtzzIIdMDGGS>3I?r(   c                    | j                  |dd      5  t        |j                        D ]  \  }}| j                  |       ||j                  d   ur0| j	                  |d|z  | j
                  d| j
                  gd       X| j                  |d	ddt        |j                        d
k(          	 d d d        y # 1 sw Y   y xY w)Nr  Tr  r@   rE  r   r   r   r  r9   )r  r   )r   r   r  rV   r_   r\   r   r   r  s       r"   visit_TuplezBaseVisitor.visit_Tuple  s    	D&	6 	;dii( ;&!S

3diim#
))D*q.477C*A   " 

dL#6:&)$))n&9  ;;	; 	; 	;s   BB;;Cc                     t         j                  t        |j                           d   }| j	                  |d|| j
                  g|d       | j                  |j                         y )Nr   r/  r  r   )r   r.  r  r/  r_   r\   rV   operandr  s      r"   visit_UnaryOpzBaseVisitor.visit_UnaryOp  sN    11$tww-@CIIIdD9dgg.	IPJJt||r(   c                 &    | j                  d       y )N...r>  r   s     r"   visit_EllipsiszBaseVisitor.visit_Ellipsis  s    JJur(   c                 `    | j                  t        j                  t        |         d          y Nr   rx   r   r.  r  r   s     r"   	visit_AddzBaseVisitor.visit_Add  "    JJ}00d<Q?@r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_SubzBaseVisitor.visit_Sub  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   
visit_MultzBaseVisitor.visit_Mult  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_DivzBaseVisitor.visit_Div  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_ModzBaseVisitor.visit_Mod  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_PowzBaseVisitor.visit_Pow  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_LShiftzBaseVisitor.visit_LShift  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_RShiftzBaseVisitor.visit_RShift  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_BitAndzBaseVisitor.visit_BitAnd  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_BitOrzBaseVisitor.visit_BitOr  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_BitXorzBaseVisitor.visit_BitXor  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_FloorDivzBaseVisitor.visit_FloorDiv   r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_InvertzBaseVisitor.visit_Invert  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_NotzBaseVisitor.visit_Not  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   
visit_UAddzBaseVisitor.visit_UAdd	  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   
visit_USubzBaseVisitor.visit_USub  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_EqzBaseVisitor.visit_Eq  r  r(   c                 L    | j                  |d| j                  dd      g       y )Nr,  z!=z<>)r_   r   r   s     r"   visit_NotEqzBaseVisitor.visit_NotEq  s"    IIdJ!4!4T4!@ ABr(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_LtzBaseVisitor.visit_Lt  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_LtEzBaseVisitor.visit_LtE  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_GtzBaseVisitor.visit_Gt  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   	visit_GtEzBaseVisitor.visit_GtE  r  r(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_IszBaseVisitor.visit_Is!  r  r(   c                 H    | j                  |dd| j                  dgd       y )Ncontentisnotzis notr   r_   r\   r   s     r"   visit_IsNotzBaseVisitor.visit_IsNot$  s!    IIdIdggu5xIHr(   c                 `    | j                  t        j                  t        |         d          y r  r  r   s     r"   visit_InzBaseVisitor.visit_In'  r  r(   c                 H    | j                  |dd| j                  dgd       y )NrI  rK  r   znot inr   rL  r   s     r"   visit_NotInzBaseVisitor.visit_NotIn*  s!    IIdItww5xIHr(   c                    g }|j                   j                  d      }|d d D ]  }|| j                  || j                  dgz  }! || j                  |d   gz  }| j                  |d|d|j                          |j                  H| j                  |d| j                  d| j                  gd	       | j                  |j                         y y )
Nr   r@   r   r   r   asnamer   r   r   )r   re  r\   r_   rS  rx   )r   r   name_patternrg  rh  s        r"   visit_aliaszBaseVisitor.visit_alias1  s    LIIOOC Ecr
 4twwdggs33l4TWWeBi((LIIdFLii  ! {{
iih$ 8&iI
jj r(   c                     | j                  |j                         |j                  H| j                  |d| j                  d| j                  gd       | j                  |j                         y y )Nannotation_prefixr   r4  r   )rx   r  r6  r_   r\   rV   r   s     r"   	visit_argzBaseVisitor.visit_arg>  s[    JJtxx"
ii)DGGS$''+B  
jj! #r(   c           
      	   t        |dg       }t        |dg       }t        |      t        |      k(  sJ t        t        |j                  |z         t        t        |dg             |j                  rdnd|j
                  rdndf      }d}t        |dg       |j                  z   }|j                  r|d t        |j                          n|}|j                  r#|j                  t        |j                         d  n|j                  }|D ]  }	| j                  |	       |dz  }||k  r/| j                  |d|z  | j                  d| j                  gd	       |t        t        |dg             k(  sg| j                  |d
| j                  d| j                  d| j                  gd	        t        t        ||j                              D ]  \  }
\  }	}| j                  |	       | j                  |d|
z  | j                  d| j                  gd	       | j                  |       |dz  }||k  se| j                  |d|z  | j                  d| j                  gd	        |j                  r| j                  |d| j                  d| j                  gd	       t        |j                  t        j                        r| j                  |j                         n9| j                  |j                         | j                  |d| j                  g       |dz  }||k  rJ| j                  d       n8|r6| j                  |d| j                  d| j                  d| j                  g       t        t        ||            D ]  \  }
\  }	}| j                  |	       |@| j                  |d|
z  | j                  d| j                  gd	       | j                  |       |dz  }||k  sg| j                  |d|z  | j                  d| j                  gd	        |j
                  r| j                  |d| j                  d| j                  gd	       t        |j
                  t        j                        r| j                  |j
                         y | j                  |j
                         | j                  |d| j                  g       y y )Nr   kw_defaultsposonlyargsr9   r   rE  r   r   r   posonly_sep/z/, z
default_%dr%  vararg_prefixr  vararg_suffix
kwonly_sepzkw_default_%dkwarg_prefixr  kwarg_suffix)rD   r   r   r   r   r   defaultsrV   r_   r\   r   r   r   r   r  rx   )r   r   r   rZ  
total_argsarg_ipos_args
positionalr   r  r   r   s               r"   visit_argumentszBaseVisitor.visit_argumentsF  s    |R0J$r2Kz?c+....c$))j01'$r:;;;aA::a1. /J Et]B/$));H37==.C../hJ15diiT]]++,-DIIG !
jjoqje				$
U*TWWc477,C 	 	 	#gdM267	7		$dggsDGG'L 	 	!! 's7DMM'BC  >C
jjo
iilQ&#tww(?  
jjqje				$
U*TWWc477,C 	 	   {{
iiodgg'>iL	DKK	)

4;;

4;;		$$''3qje		

3	 iilTWWc477C$IJ&s:{'CD 	 >C
jjo				$!+dggsDGG-D 	 	

7qje				$
U*TWWc477,C 	 	 	  zz
iintwwdgg&>iM	DJJ	(

4::

4::		$	2 r(   c           	      f   t        |dd      r9| j                  |d| j                  d| j                  d| j                  gd       n,| j                  |d| j                  d| j                  gd       | j                  |j                         | j                  |d| j                  d| j                  gd	       | j                  |j
                         t        |j                        D ]E  \  }}| j                  |d
|z  | j                  d| j                  gd       | j                  |       G y )Nis_asyncFr   r   z async for r   z for r   r   zif_%dr   r  )rD   r_   r\   rV   r   r   r   ifs)r   r   r   if_exprs       r"   visit_comprehensionzBaseVisitor.visit_comprehension  s    tZ'
iiedggwH%  ' iiedggudgg6iHJJt{{IIdD477D$''2FICJJtyy) 
7
iigkDGGT477#;ViL
jjr(   c                    |j                   "| j                  |dd| j                  gd       n<| j                  |j                          | j                  |d| j                  dgd       | j	                  |j
                         y )Nstarsr  r   eqr%  )r  r_   r\   rx   rV   r(  r   s     r"   visit_keywordzBaseVisitor.visit_keyword  sd    xx
iigdggi=
jj
iidTWWcNCi8JJtzzr(   c                 :    | j                  |j                         y r*   rO  r   s     r"   visit_IndexzBaseVisitor.visit_Index  rQ  r(   c                    t        |j                        D ]W  \  }}| j                  |       ||j                  d   us)| j                  |d|z  | j                  d| j                  gd       Y | j                  |ddd       y )Nr@   z
dim_sep_%dr   r   r   r   F)r   dimsrV   r_   r\   r   )r   r   r   dims       r"   visit_ExtSlicezBaseVisitor.visit_ExtSlice  s}    DII& Q3
jjo	DIIbM	!		$q(477C*A4	PQ 	.UCr(   c                 V   |j                   r| j                  |j                          | j                  |d| j                  d| j                  gd       |j                  r| j                  |j                         | j                  |d| j                  g       | j                  |dd       | j                  |d| j                  g       |j                  rT| j                  |      rB| j                  |ddd       d|j                  _        | j                  |j                         y y y )	N
lowerspacer   r   
stepspace1
step_colon
stepspace2step_colon_2T)	lowerrV   r_   r\   upperr   stepcheck_slice_includes_stepis_explicit_stepr   s     r"   visit_SlicezBaseVisitor.visit_Slice  s    zz
jjIIdL477C"93IGzz
jjIIdL477),lC0IIdL477),yyT33D9
$TB#'dii 
jj :yr(   c                     |j                   syt        |j                   dd      ryt        |j                   t        j                        xr |j                   j
                  dk(   S )FHelper function for Slice node to determine whether to visit its step.Fr  TNone)r  rD   r   r   Namer  r   s     r"   r  z%BaseVisitor.check_slice_includes_step  sL    
 99tyy,e4499chh/JDIILLF4JKKr(   c           	         | j                  |j                         |j                  dk7  rC| j                  |d| j                  dt        |j                        gdd|j                  z         |j                  rH| j                  |d| j                  d| j                  gd	       | j                  |j                         y y )
Nr@   
conversion!)r  z!%cr   format_spec_prefixr   r   )rV   r(  r  r_   r\   chrformat_specr   s     r"   visit_FormattedValuez BaseVisitor.visit_FormattedValue  s    JJtzz"
iil#s4??34?/  1 
ii*TWWc477,C  
jj!!" r(   )r   )NFFr   NFFNNNFT)F)__name__
__module____qualname____doc__abcABCMeta__metaclass__rR   rV   r   r   rl   rn   r%   contextmanagerr   rx   r_   r\   r   r   r   r   r;   r   rJ   r   abstractmethodr   r   r   r   r   r   r   r   r   r5   r   r   r   r   r  r  r	  r  r!   r  r  r#  r*  r1  r7  r/   r;  r?  rB  rF  rM  rP  rZ  r`  ri  rk  rn  rq  rz  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)  r+  r-  r/  r1  r3  r5  r7  r9  r;  r=  r?  rA  rC  rE  rG  rM  rO  rQ  rU  rX  rh  rm  rq  r7   rs  rw  r  r  r2   r  __classcell__rX   s   @r"   rL   rL   o   s   	 ++-%%
P CH6)' 7 7((2	 : 
 
  .  (    *   &! 	 	  $  % %  6 ! !F(  $    *  "  	               O O " "   * * I I K K4  
 * *   G G"        
   < < 9 92'R   A A  ? ?       
? 
? : :%       ? ?
 > > : : @ @ 
; 
;    AAAAAAAAAAAAAAAAACAAAAAIAI " " D3 D3L       D D  	L 	# 	#r(   rL   c                       e Zd ZdZy)AnnotationErrorz5An exception for when we failed to annotate the tree.N)r  r  r  r  r+   r(   r"   r  r    s    =r(   r  c                        e Zd Z fdZ fdZd Zed        Zed        Zed        Z	ed        Z
e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dZddZd Z xZS )AstAnnotatorc                 ^    t         t        |           t        j                  |      | _        y r*   )rU   r  rR   r
   TokenGeneratortokens)r   sourcerX   s     r"   rR   zAstAnnotator.__init__  s"    	,&(!008DKr(   c                 
   	 t        j                  |d| j                         t        j                  |d| j                         t        t
        |   |       y # t        t        t        t        f$ r}t        |      d }~ww xY w)NrI   rd   )rE   r   r   rO   rU   r  rV   	TypeError
ValueError
IndexErrorKeyErrorr  )r   r   erX   s      r"   rV   zAstAnnotator.visit  se    	ggdHdll+	ggdM4#4#45L$%d+z:x8 As   AA B2A==Bc              #     K   t        ||      }| j                  j                  }| j                  j                         j                  }|d   |d   k(  r&| j
                  }d| _        |D ]  }|  || _        y| j                  }| j
                  }	| j                  j                  d       }
|
j                  }t        ||      }|s#d}t        d|d   z  t        j                         || _        || _        |D ]  }|  t        j                  |d|z  | j                  j                  | j                               || _        |	| _        yw)zCGenerator which annotates child nodes with their indentation level.r   Nc                 P    | j                   t        j                  j                  k(  S r*   )r  r
   TOKENSINDENT)ts    r"   r]   z'AstAnnotator.indented.<locals>.<lambda>  s    !&&O22999 r(   z    zbIndent detection failed (line %d); inner indentation level is not more than the outer indentation.)filere   )rD   r  _locpeek_non_whitespacestartrO   r   peek_conditionalsrc_get_indent_diffrt  r  stderrrE   r   block_whitespace)r   r   rf   rg   cur_locnext_locrd   rk   rh   ri   indent_token
new_indentrj   s                r"   rl   zAstAnnotator.indented  sO    t]+HkkG{{..066H qzXa[ %%kd %%d,,K(( ;;//9;L!!JZ8Hh /18<BE**N DL D k GGD#m3KK((68 DL(Ds   EEc           	          t         j                  j                   fdg} j                  j	                         j
                  dk(  r|j                  dd        j                  |d|dt        |j                               y)z1Annotate a Num node with the exact number format.c                  N     j                   j                        j                  S r*   )r  next_of_typer  )r   token_number_types   r"   r]   z(AstAnnotator.visit_Num.<locals>.<lambda>  s    4;;334EFJJ r(   -r   rI  )r  r   N)
r
   r  NUMBERr  peekr  insertr_   r  r  )r   r   contentargsr  s   `  @r"   	visit_NumzAstAnnotator.visit_Num  sh     (..55JKK{{$C IIdI{TVVIMr(   c                 n    | j                  |d| j                  j                  gd|j                         y)z1Annotate a Str node with the exact string format.rI  sr   Nr_   r  r  r  r   s     r"   	visit_StrzAstAnnotator.visit_Str  )     	IIdI0vtvvINr(   c                 8    | j                   j                                }dd |j                  D        }	 t        |      \  }}|z  |n5| j                   }|| _         | j	                  t        |             || _         K| j                  |dfdg       y)z<Annotate a JoinedStr node with the fstr formatting metadata.r   c              3   V   K   | ]!  }t        |t        j                        s| # y wr*   )r   r   FormattedValue).0vs     r"   	<genexpr>z/AstAnnotator.visit_JoinedStr.<locals>.<genexpr>&  s     JA
1c6H6H(IaJs   ))NrI  c                       S r*   r+   )ress   r"   r]   z.AstAnnotator.visit_JoinedStr.<locals>.<lambda>1  s     r(   r   )r  fstrrx  nextrV   r_   )r   r   	fstr_iterrx  res_parttgprev_tokensr  s          @r"   visit_JoinedStrzAstAnnotator.visit_JoinedStr!  s     #  "$I
CJJF
)_lh	Xoc	KKkdk
jjfdk  	IIdI}cI:r(   c                 n    | j                  |d| j                  j                  gd|j                         y)z3Annotate a Bytes node with the exact string format.rI  r  r   Nr  r   s     r"   visit_ByteszAstAnnotator.visit_Bytes3  r  r(   c                     | j                   j                         j                  dk(  r| j                  d       y t	        d      D ]  }| j                  d        y )Nr  r  r   )r  r  r  rx   r  )r   r   r   s      r"   r  zAstAnnotator.visit_Ellipsis8  sI     {{&
jjQx !

3r(   c                     | j                   j                         }t        |t        j                        xr |j
                  dk(  S )z7Return True iff the If node is an `elif` in the source.r   )r  	next_namer   r   r   r  )r   r   next_toks      r"   r   zAstAnnotator.check_is_elifB  s3    {{$$&HdCFF#>(>>r(   c                     t        |t        j                        xr' | j                  j	                         j
                  dk7  S )zFReturn True iff the TryExcept node is a continued `try` in the source.r   )r   r   	TryExceptr  r  r  r   s     r"   r   z#AstAnnotator.check_is_continued_tryG  s5    tS]]+ ;KK++-11U:<r(   c                     t        |t        j                        xr' | j                  j	                         j
                  dk(  S )zBReturn True iff the With node is a continued `with` in the source.r   )r   r   Withr  r  r  r   s     r"   r   z$AstAnnotator.check_is_continued_withL  s0    dCHH%G$++*:*:*<*@*@C*GGr(   c                 N    | j                   j                         j                  dvS )r  z],)r  r  r  r   s     r"   r  z&AstAnnotator.check_slice_includes_stepP  s"    
 ;;**,00<<r(   c                    | j                   j                         }|r|r|j                  dk(  r| j                   j                         | j	                  d      z   }| j                   j                         }|j
                  t        j                  j                  t        j                  j                  fv r|| j                   j                  d      z  }|S | j                   j                  ||      S )z;Parse some whitespace from the source tokens and return it.;r9   r   )r   r   )
r  r  r  
whitespacerx   r  r
   r  NLNEWLINE)r   r   r   r   
next_tokenresults         r"   r\   zAstAnnotator.wsW  s    !!#JZJNNc$9{{%%'$**S/9f;;##%j	_3366,33;;= 
=$++((1(55m;;!!Iw!GGr(   c                       fd}|S )zParse a number of dots.c                  :    j                   j                         S r*   )r  r   )r   r   s   r"   _parse_dotsz&AstAnnotator.dots.<locals>._parse_dotse  s    [[h''r(   r+   )r   r   r  s   `` r"   r   zAstAnnotator.dotsc  s    (r(   c                 d    t        j                  |d| j                  j                  |             y )Nr   )rE   r   r  r  )r   r   indent_levels      r"   r>   zAstAnnotator.block_suffixi  s!    GGD(DKK88FGr(   c                    | j                   j                         }|j                  |k7  r3t        d||j                  |j                  d   |j
                  fz        |j                  dv r&| j                   j                          |j                  S |j                  dv r| j                   j                          |j                  S )z2Parse a single token with exactly the given value.z$Expected %r but found %r
line %d: %sr   z({[z)}])r  r  r  r  r  line	hint_openhint_closed)r   rw   rx   s      r"   rx   zAstAnnotator.tokenl  s    KKEyyIC
UYYA

G< < = = yyE
kk 99 
e	
kk99r(   c                    ~t        j                  ||d       |r| j                  j                         n| j                  j	                         }|ru|j
                  |k(  red}|r|| j                         z  }t        j                  |||| j                  j                         j
                  z   | j                         z          yyy)z/Try to parse a token and attach it to the node.r   N)rE   rT   r  r  r  r  r\   r  )r   r   r{   rw   r  r   rx   parseds           r"   r   zAstAnnotator.optional_token{  s     	JJtY#' [[,,.-1[[-=-=-? 
i'f	 $'')	jjy!DKK$4$4$6$:$::TWWYFH	 (ur(   c                       fd}|S )r   c                      j                   j                         t        fdD        d       } | t        ddj                        | S )Nc              3   B   K   | ]  }|j                   k(  s|  y wr*   )r  )r  r  r  s     r"   r  zGAstAnnotator.one_of_symbols.<locals>._one_of_symbols.<locals>.<genexpr>  s     >!!z~~*=A>s   zExpected one of: z, but found: )r  r  r  r  )foundr  r   r   s    @r"   _one_of_symbolsz4AstAnnotator.one_of_symbols.<locals>._one_of_symbols  sL    ;;##%j>w>Ee	4;Z^^LN 	Nlr(   r+   )r   r   r  s   `` r"   r   zAstAnnotator.one_of_symbols  s     r(   c           
      b   ~|r,|D ]'  }t        j                  ||dz   t        ||d             ) g }|D ]S  }t        |t        j
                        r!|j                  | j                  |             >|j                   |              U t        j                  ||dj                  |             y)a7  Parses some source and sets an attribute on the given node.

    Stores some arbitrary formatting information on the node. This takes a list
    attr_vals which tell what parts of the source to parse. The result of each
    function is concatenated onto the formatting data, and strings in this list
    are a shorthand to look for an exactly matching token.

    For example:
      self.attr(node, 'foo', ['(', self.ws, 'Hello, world!', self.ws, ')'],
                deps=('s',), default=node.s)

    is a rudimentary way to parse a parenthesized string. After running this,
    the matching source code for this node will be stored in its formatting
    dict under the key 'foo'. The result might be `(
  'Hello, world!'
)`.

    This also keeps track of the current value of each of the dependencies.
    In the above example, we would have looked for the string 'Hello, world!'
    because that's the value of node.s, however, when we print this back, we
    want to know if the value of node.s has changed since this time. If any of
    the dependent values has changed, the default would be used instead.

    Arguments:
      node: (ast.AST) An AST node to attach formatting information to.
      attr_name: (string) Name to store the formatting information under.
      attr_vals: (list of functions/strings) Each item is either a function
        that parses some source and return a string OR a string to match
        exactly (as a token).
      deps: (optional, set of strings) Attributes of the node which attr_vals
        depends on.
      default: (string) Unused here.
    __srcNr   )	rE   r   rD   r   sixstring_typesrT   rx   join)	r   r   r{   r|   r}   r   dep
attr_partsattr_vals	            r"   r_   zAstAnnotator.attr  s    @ 	 ?#cGmWT3%=>?J &	Hc..	/$**X./(*%	&
 GGD)RWWZ01r(   c                 @    ~| j                   j                  |||      S )aK  Return a context manager to handle a parenthesized scope.

    Arguments:
      node: (ast.AST) Node to store the scope prefix and suffix on.
      attr: (string, optional) Attribute of the node contained in the scope, if
        any. For example, as `None`, the scope would wrap the entire node, but
        as 'bases', the scope might wrap only the bases of a class.
      trailing_comma: (boolean) If True, allow a trailing comma at the end.
      default_parens: (boolean) If True and no formatting information is
        present, the scope would be assumed to be parenthesized.
    )r_   r   )r  r   rt   s        r"   r   zAstAnnotator.scope  s#     	;;T^LLr(   c                     | j                   j                         }|r|j                  |k7  s|j                  |k7  ry| j                   j	                          |j                  | j                         z   S )Nr   )r  r  r  r  r  r\   )r   
token_typerw   rx   s       r"   _optional_tokenzAstAnnotator._optional_token  sU    KKEEJJ*,		Y0F
kkYY""r(   r  )FFr  r  )r  r  r  rR   rV   rl   r/   r  r  r  r  r5   r  r   r   r   r  r\   r   r>   rx   r   r   r_   r   r	  r  r  s   @r"   r  r    s    9')R N N O O ; ;" O O  ?
<
H=
HH  =BH	*2XM#r(   r  c                 P    d}| D ]  }|dk(  r|dz  }|dk(  s|d|dz  z
  z  }  |S Nr   r   r9   	   r+   )rI   widthcs      r"   _get_indent_widthr    sF    
% aCxqje	
dqEAIe	
 
,r(   c                     d}t        |       D ]L  \  }}||k(  r nB|dk(  r|dz  }|dk(  s|dz   |dz  z
  |k  r|d|dz  z
  z  }8d|dz   |z
  z  | |dz   d  z   c S  | d  S r  )r   )rI   remove_widthr  r   r  s        r"   _ltrim_indentr    s    
% 	AdaCxqje	
d	eai	 L	0eai eai,./&Q.@@	A 
r(   c                 b    t        |       }t        |      }||z
  }|dk  ryt        |||z
        S )aK  Computes the whitespace added to an indented block.

  Finds the portion of an indent prefix that is added onto the outer indent. In
  most cases, the inner indent starts with the outer indent, but this is not
  necessarily true. For example, the outer block could be indented to four
  spaces and its body indented with one tab (effectively 8 spaces).

  Arguments:
    outer: (string) Indentation of the outer block.
    inner: (string) Indentation of the inner block.
  Returns:
    The string whitespace which is added to the indentation level when moving
    from outer to inner.
  r   N)r  r  )outerinnerouter_winner_wdiff_ws        r"   r  r    s>     e$'e$'W&q[	ug.	//r(   )TTTNFFF)&r  
__future__r   r   r   r  r   r%   r  	itertoolsr   	six.movesr   r  
pasta.baser   r   r	   rE   r
   r'   r  r   r/   r2   r5   r7   r!   r;   rJ   NodeVisitorrL   	Exceptionr  r  r  r  r  r+   r(   r"   <module>r      s    H '  % 
 
    
  
 $   ( & LP;@  -
&
&
4
44
*f##// f#R#>i >y#; y#x0r(   