
    -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
 ddl	mZ d	 Zd
 Zd ZdS )z Rename names in a python module.    )absolute_import)division)print_functionN)import_utils)	ast_utils)scopec                    t          j        |           }||j        vrdS d}i }g }|j        |         D ]}t          |j        t
          j                  r|                    |j                  }t          |t
          j                  rg||vrct          ||||          sJ |
                    dd          d         ||
                    dd          d         <   |                    |           n?||j        j        t          |          d         z   |j        _        |j        j        s|||<   d}t          |j        t
          j                  rw|j        |vrnt          ||j        ||          sJ |
                    dd          d         ||
                    dd          d         <   |                    |j                   d}t          j        |          D ]\  }	}
t#          || |	|
           |S )a  Rename an imported name in a module.

  This will rewrite all import statements in `tree` that reference the old
  module as well as any names in `tree` which reference the imported name. This
  may introduce new import statements, but only if necessary.

  For example, to move and rename the module `foo.bar.utils` to `foo.bar_utils`:
  > rename_external(tree, 'foo.bar.utils', 'foo.bar_utils')

  - import foo.bar.utils
  + import foo.bar_utils

  - from foo.bar import utils
  + from foo import bar_utils

  - from foo.bar import logic, utils
  + from foo.bar import logic
  + from foo import bar_utils

  Arguments:
    t: (ast.Module) Module syntax tree to perform the rename in. This will be
      updated as a result of this function call with all affected nodes changed
      and potentially new Import/ImportFrom nodes added.
    old_name: (string) Fully-qualified path of the name to replace.
    new_name: (string) Fully-qualified path of the name to update to.

  Returns:
    True if any changes were made, False otherwise.
  F.   NT)r   analyzeexternal_references
isinstancenodeastaliasparent
ImportFrom_rename_name_in_importfromrsplitappendnamelenasnamesix	iteritems_rename_reads)told_namenew_nameschas_changedrenamesalready_changedrefr   
rename_old
rename_news              Z/var/www/html/movieo_spanner_bot/venv/lib/python3.11/site-packages/pasta/augment/rename.pyrename_externalr)      s   < }Q"R+++5+'/#H-  c#(CI&& yy""f 
FCN	+	+ 'o0M0M)"fhIIIII/7sA/F/Fr/JQ''+,v&&&& 38=X#@@x 	'&'(
kk	CHcn	-	- 		(	()"ch(KKKKK/7sA/F/Fr/JQ''+,sx((( #g 6 6 1 1j*"aZ0000	    c                    ||k    rdS |j                             d          }|                    d          }|                    d          }|d t          |                   |k    r4d                    ||t          |          d          z             |_         dS |j        D ]}|j        |d         k    r ndS |d         |_        ||d d         k    rst          |j                  dk    r9t          j        | ||          }d                    |d d                   |_         n"d                    |d d                   |_         dS )NFr
   Tr   r   )modulesplitr   joinnamesr   r   split_import)	r!   r   r   r    module_parts	old_parts	new_partsalias_to_change
new_imports	            r(   r   r   ^   sN   5""3'',nnS!!)nnS!!) /3y>>/"i//((9|C	NNOO'DDEEDK4   oy},,e - 5"2/ Yss^##
4:,RGGj((9SbS>22jHHYss^,,dk	r*   c                    |                     d          }	 | j        |d                  }|dd         D ]}|j        |         }n# t          $ r Y dS w xY wd}|j        D ]u}t          |t          j        t          j        f          rMt          j
        |                     |          |t          j        |          j        d         j                   d}v|S )ap  Updates all locations in the module where the given name is read.

  Arguments:
    sc: (scope.Scope) Scope to work in. This should be the scope of `t`.
    t: (ast.AST) The AST to perform updates in.
    old_name: (string) Dotted name to update.
    new_name: (string) Dotted name to replace it with.

  Returns:
    True if any changes were made, False otherwise.
  r
   r   r   NFT)r-   r/   attrsKeyErrorreadsr   r   Name	Attributer   replace_childr   parsebodyvalue)	r!   r   r   r    
name_partsr   partr"   ref_nodes	            r(   r   r      s     ~~c""*8JqM"D122  Zdd	   55 +*  h(SXs}566 bii118!i116q9?A A Ak	s   -A 
AA)__doc__
__future__r   r   r   r   r   pasta.augmentr   
pasta.baser   r   r)   r   r    r*   r(   <module>rH      s    & & ' & & & & &       % % % % % % 



 



 & & & & & &                  > > >B  B    r*   