
    -Sh|                     T   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mZ ddl	m
Z  ej        d          Zej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej        ej         ej!        ej"        ej#        ej$        ej%        ej&        ej'        ej(        ej)        fZ* G d	 d
ej+                  Z, e,            Z-d Z.d Z/d Z0 G d dej1                  Z2d Z3d Z4d Z5d Z6dS )z%Helpers for working with python ASTs.    )absolute_import)division)print_functionN)errors)
formattingz+^[ 	]*#.*?coding[:=][ 	]*([-_.a-zA-Z0-9]+)c                   "     e Zd ZdZ fdZ xZS )_TreeNormalizerz,Replaces all op nodes with unique instances.c                     t          |t                    r|                                S t          t          |                               |          S N)
isinstance_AST_OP_NODES	__class__superr	   visitselfnoder   s     Z/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/pasta/base/ast_utils.pyr   z_TreeNormalizer.visit*   sC    $&& ^^$''--d333    )__name__
__module____qualname____doc__r   __classcell__r   s   @r   r	   r	   '   s>        444 4 4 4 4 4 4 4 4r   r	   c                 |    t          j        t          |                     }t                              |           |S )zReplaces ast.parse; ensures additional properties on the parsed tree.

  This enforces the assumption that each node in the ast is unique.
  )astparsesanitize_source_tree_normalizerr   )srctrees     r   r   r   3   s4    
 
?3''	(	($	+r   c                     |                      d          }t          |dd                   D ]8\  }}t                              |          rt	          j        dd|          ||<   9d                    |          S )zStrip the 'coding' directive from python source code, if present.

  This is a workaround for https://bugs.python.org/issue18960. Also see PEP-0263.
  TN   z#.*$z# (removed coding) )
splitlines	enumerate_CODING_PATTERNmatchresubjoin)r!   	src_linesilines       r   r   r   =   s|    
 nnT"")9RaR=)) @ @gaT"" @VF$8$??il			r   c                 `    t          fd          }|                    |            |j        S )Nc                 $    t          |           S r   )r   )naccept_typess    r   <lambda>z$find_nodes_by_type.<locals>.<lambda>J   s    jL&A&A r   )FindNodeVisitorr   results)r   r3   visitors    ` r   find_nodes_by_typer8   I   s4    AAAABB'	--	r   c                   $     e Zd Zd Z fdZ xZS )r5   c                 "    || _         g | _        d S r   )
_conditionr6   )r   	conditions     r   __init__zFindNodeVisitor.__init__Q   s    DODLLLr   c                     |                      |          r| j                            |           t          t          |                               |           d S r   )r;   r6   appendr   r5   r   r   s     r   r   zFindNodeVisitor.visitU   sQ    t  
l$	/4  &&t,,,,,r   )r   r   r   r=   r   r   r   s   @r   r5   r5   O   sG          - - - - - - - - -r   r5   c                    t          | t          j                  r	 | j        d         S # t          $ r Y dS w xY wt          | t          j                  rt          | j                  dk    r_t          | j        d         t          j                  r:t          j	        | j        d         d          rt          | j        d                   S | j        r| j        d         S nt          | t          j                  ryt          | j                  dk    r_t          | j        d         t          j                  r:t          j	        | j        d         d          rt          | j        d                   S n t          t          d          rCt          | t          j                  r)| j        r| j        d         S | j        r| j        d         S nt          t          d          r/t          | t          j                  r| j        r| j        d         S ndt          t          d	          rOt          | t          j                  r5| j        r| j        d         S | j        rt          | j        d                   S | j        d         S )
aR  Get the last child node of a block statement.

  The input must be a block statement (e.g. ast.For, ast.With, etc).

  Examples:
    1. with first():
         second()
         last()

    2. try:
         first()
       except:
         second()
       finally:
         last()

  In both cases, the last child is the node for `last`.
  N   r   is_elifis_continuedTry
TryFinally	TryExcept)r   r   Modulebody
IndexErrorIflenorelsefmtgetget_last_childWithhasattrrE   	finalbodyrF   rG   handlersr   s    r   rP   rP   [   s?   & cj!! Yr]   TTcf /DKA*T[^SV"D"DA	** 	DKN+++{ [_$!! /DI!
49Q< B B	!n-- 	DIaL)))sE /z$88 /~  ^B{ [_sL!! /js~&F&F /~  ^B sK   /Zcm%D%D /{ [_} /DM"-...	2s   ) 
77c                     t          j        |           D ]6\  }}t          |t                    r||v r|                    |            d S 7t          j        d|d|           )Nz%Unable to find list containing child z on parent node )r   iter_fieldsr   listremover   InvalidAstError)parentchild_field_values       r   remove_childr_      s    //  na+t$$ +)=)=ff3855&& B 	C 	C Cr   c                    t          |t          j                  rRt          j        |dt          j        |d                     t          j        |dt          j        |d                     | j        D ]n}t          | |d          }||k    rt          | ||            dS t          |t                    r,	 |||
                    |          <    dS # t          $ r Y jw xY wot          j        d|d|           )zReplace a node's child with another node while preserving formatting.

  Arguments:
    parent: (ast.AST) Parent node to replace a child of.
    node: (ast.AST) Child node to replace.
    replace_with: (ast.AST) New child node.
  prefixsuffixNzNode z is not a child of )rR   rN   
PASTA_DICTsetrO   _fieldsgetattrsetattrr   rX   index
ValueErrorr   rZ   )r[   r   replace_withfield	field_vals        r   replace_childrm      s    T3>"" =GL(CGD($;$;<<<GL(CGD($;$;<<<~ 
 
et,,IDfe\***ff	It	$	$ +7	)//$''(   	 	vvNOOOs   7C
CCc                     t          | d          oU| j        oNt          | j        d         t          j                  o)t          | j        d         j        t          j                  S )NrI   r   )rR   rI   r   r   ExprvalueStrrU   s    r   has_docstringrr      sT    
$

 2DI 2
TYq\38
,
,2
TYq\'
1
13r   )7r   
__future__r   r   r   r   r*   pasta.augmentr   
pasta.baser   rN   compiler(   AndOrEqNotEqIsIsNotInNotInLtLtEGtGtEAddSubMultDivModPowLShiftRShiftBitAndBitOrBitXorFloorDivInvertNotUAddUSubr   NodeTransformerr	   r    r   r   r8   NodeVisitorr5   rP   r_   rm   rr    r   r   <module>r      s   + + ' & & & & &       % % % % % % 



 				             ( ( ( ( ( ( "*MNN GSVSVSY	3639FCGSVSWcgsw#'GSWcj#*cj#)SZL#*cgsx	4 4 4 4 4c) 4 4 4 #?$$   	 	 	  	- 	- 	- 	- 	-co 	- 	- 	-/ / /dC C CP P P43 3 3 3 3r   