
    Æeb                     \   d dl Z d dlmZ d dlZd dlmZmZmZm	Z	m
Z
mZmZmZmZ d dlmZmZ d dlmZmZmZmZmZmZmZ d Zd Z G d d	      Z G d
 de      Z G d de      Z G d de      Zdee    de fdZ! G d d      Z" G d d      Z# G d d      Z$	 ddZ%d Z&d Z'd Z(d Z)d Z*y)     N)List)	codeanalyzeevaluate
exceptionslibutilspynames	pyobjects
taskhandleutilsworder)ChangeContents	ChangeSet)change_signaturefunctionutilsimportutilsmoveoccurrencesrenamesourceutilsc               #   B   K   d} 	 dt        |       z   dz    | dz  } w)Nr   __   )str)ns    6/usr/lib/python3/dist-packages/rope/refactor/inline.pyunique_prefixr   .   s/     	A
SVmd""	Q s   c                    t        | ||      }d}|t        j                  |      t        |t        j
                        r|j                         }t        |t        j                        rt        | ||      S t        |t        j                        rt        | ||      S t        |j                         t        j                        rt        | ||      S t        j                  |      )zCreate a refactoring object for inlining

    Based on `resource` and `offset` it returns an instance of
    `InlineMethod`, `InlineVariable` or `InlineParameter`.

    zPInline refactoring should be performed on a method, local variable or parameter.)_get_pynamer   RefactoringError
isinstancer   ImportedName_get_imported_pynameAssignedNameInlineVariableParameterNameInlineParameter
get_objectr	   
PyFunctionInlineMethod)projectresourceoffsetpynamemessages        r   create_inliner/   5   s     (F3F	1  ~))'22&'../,,.&'../gx88&'//0w&99&##%y';';<GXv66))'22    c                       e Zd Zd Zd Zd Zy)_Inlinerc                     || _         t        |||      | _        t        j                  |j                         d      }|j                  |      | _        |j                  |      | _	        || _
        || _        y NT)r*   r   r-   r   Worderreadget_primary_rangeregionget_word_atnamer,   original)selfr*   r+   r,   range_finders        r   __init__z_Inliner.__init__P   sa    !'8V<}}X]]_d;"44V< ,,V4	 r0   c                      y N )r<   argskwdss      r   get_changesz_Inliner.get_changesY   s    r0   c                      y)z1Return either 'variable', 'method' or 'parameter'NrA   r<   s    r   get_kindz_Inliner.get_kind\   s    r0   N)__name__
__module____qualname__r>   rD   rG   rA   r0   r   r2   r2   O   s    !@r0   r2   c                   l     e Zd Z fdZd Zd Zdddej                  fdZd Z	d	 Z
d
 Zd Zd Z xZS )r)   c                    t        |   |i | | j                  j                         | _        | j                  j                         | _        | j                  j                         j                         | _        t        j                  | j                  | j                  | j                        | _        t        | j                  | j                        | _        | j!                          y r@   )superr>   r-   r'   
pyfunction
get_modulepymoduleget_resourcer+   r   create_finderr*   r:   occurrence_finder_DefinitionGeneratornormal_generator_init_importsr<   rB   rC   	__class__s      r   r>   zInlineMethod.__init__a   s    $'$'++002224224AAC!,!:!:LL$))T[["
 !5T\\4?? Sr0   c                     t        j                  | j                        }t        j                  | j
                  | j                  |      \  }}|| _        t        | j
                  | j                  |      | _	        y )N)body)
r   get_bodyrN   r   moving_code_with_importsr*   r+   importsrT   others_generator)r<   rZ   r]   s      r   rV   zInlineMethod._init_importsl   sZ    ##DOO455dllDMMSWXg 4LL$//!
r0   c                    | j                   j                         }| j                  j                  }|j	                         }| j                   j
                  r4| j                   j
                  }t        |d   d      r|d   j                  }|j                  |      }t        |j                  |j                        dz   t        | j                  j                              }||fS )Nr   linenor   )rN   	get_scoperP   lines	get_start
decoratorshasattrr`   get_line_startminget_line_endendlensource_code)r<   scoperb   
start_linerd   start_offset
end_offsets          r   _get_scope_rangezInlineMethod._get_scope_ranget   s    ))+##__&
??%%33Jz!}h/']11
++J7uyy)A-s4==3L3L/M

 j))r0   TFNc                 p   t        d| j                  z        }|| j                  j                         }|r*| j                  g}|r|j                  | j                         |j                  dt        |            }|D ]4  }|j                  |j                         || j                  k(  r$|j                  | j                  |||             nd}|r| j                  |k(  r| j                  }t        | j                  || j                  |      }	t!        j"                  | j$                  ||	      j'                         }
|
at)        | j                  |
|| j*                        }
|r"t-        | j                  | j.                  |
|      }
|j                  t1        ||
             |j3                          7 |S )zGet the changes this refactoring makes

        If `remove` is `False` the definition will not be removed.  If
        `only_current` is `True`, the the current occurrence will be
        inlined, only.
        zInline method <%s>NzCollecting Changes)removeonly_current)r   r:   r*   get_python_filesr;   appendr+   create_jobsetrj   started_jobpath
add_change_defining_file_changesr,   #_InlineFunctionCallsForModuleHandler^   r   ModuleSkipRenamerrS   get_changed_module_add_importsr]   _remove_fromr-   r   finished_job)r<   rr   rs   	resourcestask_handlechangesjob_setfileaimhandleresults              r   rD   zInlineMethod.get_changes   s    0499<=557II  /++,@#i.Q 	#D		*t}}$""//\ 0  DMMT$9++C<LL$(=(=s //**D&$$&  %)$,,dllSF!-dllDKKQU!V&&~dF'CD  "/	#0 r0   c                    | j                   j                         }| j                  j                  }| j	                         \  }}|j                         }t        |dz   |j                               D ](  }|j                  |      j                         dk(  r|}( n t        |j                  |      dz   t        | j                  j                              }||fS )Nr    )rN   ra   rP   rb   rp   get_endrangelengthget_linestriprg   rh   rj   rk   )r<   rl   rb   startri   end_lineis          r   _get_removed_rangezInlineMethod._get_removed_range   s    ))+##**,
s==?x!|U\\^4 	A~~a &&(B.		
 %$$X.2C8Q8Q4RSs|r0   c                    | j                         \  }}d }|rL| j                  | j                  k(  r| j                  }n&t	        | j                  j                               dz   }t        | j                  | j                  | j                  |      }d }|r| j                         }t        j                  | j                  | j                  ||||      j                         }	t        | j                  |	      S )Nd   )
aim_offset)r   r+   r;   r,   rj   r6   r{   r*   rU   _get_method_replacementr   r|   rS   r}   r   )
r<   r   rr   rs   rn   ro   r   r   replacementr   s
             r   rz   z#InlineMethod._defining_file_changes   s    #'#:#:#< j}}-kk $--,,./#54LL$--)>)>3
 668K''""MM
 

 	 dmmV44r0   c                     | j                         rXt        j                  | j                  j                  | j
                  j                         j                               }d|z  dz   S y)N zpass
r   )_is_the_last_method_of_a_classr   get_indentsrP   rb   rN   ra   rc   )r<   indentss     r   r   z$InlineMethod._get_method_replacement   sW    ..0!--##T__%>%>%@%J%J%LG =8++r0   c                 B   | j                   j                  }t        |t        j                        syt        j                  |      \  }}| j                  j                  }| j                         \  }}||| j                         dk(  xr ||| j                         dk(  S )NFr   )rN   parentr    r	   PyClassr   get_body_regionrP   rk   rp   r   )r<   pyclassclass_start	class_endsource
func_startfunc_ends          r   r   z+InlineMethod._is_the_last_method_of_a_class   s    //(('9#4#45!,!<!<W!EY**#446
H;z*002b8 9x	*002b8	
r0   c                      y)NmethodrA   rF   s    r   rG   zInlineMethod.get_kind   s    r0   )rH   rI   rJ   r>   rV   rp   r
   DEFAULT_TASK_HANDLErD   r   rz   r   r   rG   __classcell__rX   s   @r   r)   r)   `   sE    	
*  22-^52

r0   r)   c                   b     e Zd Z fdZd Zddddej                  fdZd Zd Z	d	 Z
d
 Z xZS )r$   c                     t        |   |i | | j                  j                         d   | _        | j                  j                         | _        | j                          | j                          y Nr   )	rM   r>   r-   get_definition_locationrP   rQ   r+   _check_exceptional_conditionsrV   rW   s      r   r>   zInlineVariable.__init__   sZ    $'$';;=a@224**,r0   c                 r    t        | j                  j                        dk7  rt        j                  d      y )Nr   z4Local variable should be assigned once for inlining.)rj   r-   assignmentsr   r   rF   s    r   r   z,InlineVariable._check_exceptional_conditions   s4    t{{&&'1,--F  -r0   TFNc                     |Gt        j                  | j                        r| j                  g}n| j                  j                         }|rC| j                  g}|r4| j                  | j                  k7  r|j                  | j                         t        d| j                  z        }|j                  dt        |            }|D ]  }|j                  |j                         || j                  k(  r9| j                  |||      }	|j                  t!        | j                  |	             nR| j#                  |||      }
|
=t%        | j                  |
|| j&                        }
|j                  t!        ||
             |j)                           |S )NzInline variable <%s>zCalculating changes)r   	_is_localr-   r+   r*   rt   r;   ru   r   r:   rv   rj   rw   rx   _change_main_modulery   r   _change_moduler~   r]   r   )r<   rr   rs   r   docsr   r   jobsetr+   r   r   s              r   rD   zInlineVariable.get_changes   sJ    ,!]]O	 LL99;	I$--4==8  /2TYY>?**+@#i.Q! 
	"Hx}}-4==(11&,M"">$--#HI,,Xv|L%)$,,$,,WF&&~h'GH!
	" r0   c           	          d }|r%| j                   | j                  k(  r| j                  }t        | j                  | j
                  | j                  | j                  |||      S )N)rr   r8   r   )r;   r+   r8   _inline_variabler*   rP   r-   r:   )r<   rr   rs   r   r8   s        r   r   z"InlineVariable._change_main_module  sT    DMMT]]:[[FLLMMKKII
 	
r0   c                     t        | j                  | j                        }t        j                  | j
                  | j                  |      \  | _        | _        y r@   )	
_getvardefrP   r-   r   r\   r*   r+   importedr]   )r<   vardefs     r   rV   zInlineVariable._init_imports,  s>    DMM4;;7&*&C&CLL$--'
#t|r0   c                     t        j                         t        j                   j                        g}|r&| j                  k(  r fd}|j                  d|       t        j                   j                   j                  |      }t        j                  | j                  |d      }|r$|r"t         j                   j                  ||      }|S )Nc                 j    | j                         \  }}j                  |k  s|j                  k  ryy NF)r7   r,   )
occurrencer   ri   r<   s      r   	check_aimz0InlineVariable._change_module.<locals>.check_aim6  s4    '99;
s;;&#*;  +<r0   r   )filtersT)r+   replace_primary)r   NoImportsFilterPyNameFilterr-   r;   insertFinderr*   r:   r   rename_in_moduler   r   )r<   r+   rr   rs   r   r   finderchangeds   `       r   r   zInlineVariable._change_module2  s    ..0+2J2J4;;2WXH5!
 NN1i(##DLL$))WM))DMMHd
 v"4<<gxPGr0   c                      y)NvariablerA   rF   s    r   rG   zInlineVariable.get_kindD  s    r0   )rH   rI   rJ   r>   r   r
   r   rD   r   rV   r   rG   r   r   s   @r   r$   r$      s>     22B

$r0   r$   c                   0     e Zd Z fdZd Zd Zd Z xZS )r&   c                     t        |   |i | | j                         \  }}| j                  j                  }t        j                  |      g| _        t        j                  | j                  ||      | _
        y r@   )rM   r>   _function_locationr-   indexr   ArgumentDefaultInlinerchangersChangeSignaturer*   	signature)r<   rB   rC   r+   r,   r   rX   s         r   r>   zInlineParameter.__init__I  si    $'$'224&!!)@@GH)99LL(F
r0   c                     | j                   j                         \  }}|j                         }|j                  j	                  |      }t        j                  |j                        }|j                  |      }||fS r@   )	r-   r   rQ   rb   rf   r   r5   rk   find_function_offset)r<   rP   r`   r+   r   word_finderr,   s          r   r   z"InlineParameter._function_locationR  sj    ;;>>@&((*--f5mmH$8$8911%8r0   c                 P     | j                   j                  | j                  fi |S )zGet the changes needed by this refactoring

        See `rope.refactor.change_signature.ChangeSignature.get_changes()`
        for arguments.
        )r   rD   r   )r<   rC   s     r   rD   zInlineParameter.get_changesZ  s$     *t~~))$--@4@@r0   c                      y)N	parameterrA   rF   s    r   rG   zInlineParameter.get_kindb  s    r0   )rH   rI   rJ   r>   r   rD   rG   r   r   s   @r   r&   r&   H  s    
 Ar0   r&   rb   returnc                 $    dj                  |       S )N
join)rb   s    r   _join_linesr   f  s    99Ur0   c                   *    e Zd Zd Zd Zd Zd Zd Zy)_ComplexExpressionVisitorc                     d| _         y r   is_complex_expressionrF   s    r   r>   z"_ComplexExpressionVisitor.__init__k  s
    %*"r0   c                     d| _         y r4   r   r<   nodes     r   _Setz_ComplexExpressionVisitor._Setn  
    %)"r0   c                     d| _         y r4   r   r   s     r   _Listz_ComplexExpressionVisitor._Listq  r   r0   c                     d| _         y r4   r   r   s     r   _Tuplez _ComplexExpressionVisitor._Tuplet  r   r0   c                     d| _         y r4   r   r   s     r   _Dictz_ComplexExpressionVisitor._Dictw  r   r0   N)rH   rI   rJ   r>   r   r   r   r   rA   r0   r   r   r   j  s    +****r0   r   c                   d    e Zd Z e       ZddZd Zd Zd ZddZd Z	d Z
d	 Zd
 Zed        Zy)rT   Nc                 F   || _         || _        |j                         | _        | j                  j	                         | _        | j                         | _        | j                         | _	        i | _
        ||| _        y t        j                  | j                        | _        y r@   )r*   rN   rO   rP   rQ   r+   _get_definition_infodefinition_info_get_definition_paramsdefinition_params_calculated_definitionsrZ   r   r[   )r<   r*   rN   rZ   s       r   r>   z_DefinitionGenerator.__init__~  s    $"--/224#88:!%!<!<!>')$DI#,,T__=DIr0   c                 T    t         j                  j                  | j                        S r@   )r   DefinitionInfor6   rN   rF   s    r   r   z)_DefinitionGenerator._get_definition_info  s    ++00AAr0   c                 p   | j                   }t        |j                  D cg c]  }| c}      }|j                  |j                  t        j                  d      | j                  j                         dk(  r7| j                  j                  j                         ||j                  d   d   <   |S c c}w )Nz8Cannot inline functions with list and keyword arguments.classmethodr   )r   dictargs_with_defaultsargs_argkeywords_argr   r   rN   rG   r   get_name)r<   r   pair	paramdicts       r   r   z+_DefinitionGenerator._get_definition_params  s    ..?+M+MN4$NO	$$0++7--J  ??##%6 &&//1 2215a8  Os   	B3c                 6    | j                   j                         S r@   )rN   r  rF   s    r   get_function_namez&_DefinitionGenerator.get_function_name  s    ''))r0   c                 4    |g }| j                  |||||      S r@   )_calculate_definition)r<   primaryr-   call	host_varsreturnss         r   get_definitionz#_DefinitionGenerator.get_definition  s&    I))'64GTTr0   c                    t         j                  j                  ||| j                  |      }| j                  }t        j
                  | j                  |      }|j                  j                         D ]
  \  }}|||<    d}	g }
|j                         D ]=  \  }}||k7  s||	|dz   |j                  dd      z   dz   z  }	|
j                  |       ? |	|
fS )Nr   z = r   r   )
r   CallInfor6   r   r   ArgumentMapping
param_dictitemsreplaceru   )r<   r
  r-   r  	call_infor  mapping
param_namevalueheaderto_be_inlinedr:   s               r   _calculate_headerz&_DefinitionGenerator._calculate_header  s     "**//VT114
	 **	//0D0DiP!(!3!3!9!9!; 	*J$)Ij!	*$??, 	+KD%u}!2$,tS)AADHH$$T*	+ }$$r0   c                    | j                  |||      \  }}|| j                  z   }t        j                  | j                  |      }	|	j                         j                         }
|
D cg c]5  }t        |
|   t        j                  j                  j                        s|7 }}t        |      j                  t        |            rt        t        j                         }t        j                  | j                  || j"                        }|D cg c]  }||z   	 }}|D ]n  }||   }t%        j&                  | j                  ||      }t)        j*                  |||z   |      }t        j                  | j                  || j"                        }p |D ]J  }t        j                  | j                  || j"                        }||   }t-        | j                  |||      }L | j/                  ||      S c c}w c c}w )N)rP   )r  rZ   r   get_string_moduler*   ra   	get_namesr    ropebasebuiltinsBuiltinNamesetintersectionnextrT   r   r+   r   rR   r   r   r   _replace_returns_with)r<   r
  r-   r  r  r  r  r  r   mod	name_dictx	all_namesprefixguestitemrS   r:   rP   s                      r   r	  z*_DefinitionGenerator._calculate_definition  s    $ 6 6w M$))#((v>MMO--/	 
ilDII,>,>,J,JK 
	 
 y>&&s9~6.<<=F..t||VT]]SE7DEtVd]EME! Xt$/$=$=LL$%!  00%v}u !224<<WX " 	LD11$,,VHd^F%dllHfdKF	L
 ))&'::;
 Fs   (:G1G6c           	         g }d }d}t         j                         j                  |      D ]6  }|j                         j	                         D ]  \  }}|s
|dk(  s|j                  |||j                  d              |rq| j                  ||j                  d             |j                  d      }	t        ||	t        |       j                         j                               }t        |      }|j                  d      }
|
t        |      k  r"||
   dv r|
dz  }
|
t        |      k  r||
   dv r|
}|
t        |      k(  s
||
   dk(  s|j                  d        9 |j                  ||d         dj                  |      |fS )Nr   r   z 	r   r   passr   )rT   _get_return_patternfinditer	groupdictr  ru   r   _check_nothing_after_returnri   r   rj   lstrip
splitlinesr   )r<   r   r  r   returnedlast_changedmatchkeyr  beg_idxcurrents              r   r&  z*_DefinitionGenerator._replace_returns_with  sr   )==?HHP 	2E#oo/557 2
USH_MM&H8M"NO888ATU"'))H"5#."7S[9@@BMMO$ (+6{"'))H"5%F3w58P#qLG &F3w58P'."c&k1VG_5L"MM&1!2	2$ 	f\]+,wwv((r0   c                 (   t        j                  |      }|j                  |      }t        j                  |      }|j	                  |      d   }||j                  |      t        |       j                         dk7  rt        j                  d      y )Nr   r   z?Cannot inline functions with statements after return statement.)
r   SourceLinesAdapterget_line_numberLogicalLineFinderlogical_line_inrh   rj   r   r   r   )r<   r   r,   rb   r`   logical_liness         r   r3  z0_DefinitionGenerator._check_nothing_after_return  s    ..v6&&v.#55e<..v6q9%$$V,s6{;AACrI--V  Jr0   c                     t        | d      sQd } |ddg      } |dt        j                         g      }d}t        j                  |dz   |z   dz   |z         | _        | j
                  S )N_return_patternc                 6    d| z  dj                  |      z   dz   S )Nz(?P<%s>|)r   )r:   list_s     r   named_patternz?_DefinitionGenerator._get_return_pattern.<locals>.named_pattern  s     4'#((5/9C??r0   commentz#[^\n]*stringz\b(?P<return>return)\brE  )re   r   get_string_patternrecompilerC  )clsrH  comment_patternstring_patternreturn_patterns        r   r0  z(_DefinitionGenerator._get_return_pattern  sv    s-.@ ,I
|DO*8k6T6T6V5WXN6N"$**#%6<~M#C """r0   r@   r   )rH   rI   rJ   r   r>   r   r   r  r  r  r	  r&  r3  r   r0  rA   r0   r   rT   rT   {  sM    !OM>B *U%$#;J)2 # #r0   rT   c                       e Zd Zd	dZd Zd Zd Zeej                  d               Z
eej                  d               Zeej                  d               Zy)
r{   Nc                 <    || _         || _        || _        || _        y)zInlines occurrences

        If `aim` is not `None` only the occurrences that intersect
        `aim` offset will be inlined.

        N)r*   	generatorr+   r   )r<   r*   r+   definition_generatorr   s        r   r>   z,_InlineFunctionCallsForModuleHandle.__init__  s      - r0   c                 N    |j                         st        j                  d      y )Nz1Cannot inline functions that reference themselves)
is_definedr   r   )r<   change_collectorr   s      r   occurred_inside_skipz8_InlineFunctionCallsForModuleHandle.occurred_inside_skip  s)    $$&--C  'r0   c                    |j                         \  }}|j                         ry |j                         s.t        j                  d| j
                  j                  |fz        | j                  | j                  |k  s| j                  |kD  ry | j                  | j                  |dz
        }| j                  j                  |      }| j                  j                  j                  |      \  }}| j                  j                  |      }	| j                  j!                  |      }
| j                  |	| j#                         dk7  xs  | j                  ||
 j#                         dk7  }t%        j&                  | j                  |      }|j)                         \  }}| j                  }|j*                  j-                  |      }| j.                  j1                  ||| j                  || |j3                         |      \  }}t5        |
dz   t7        | j                              }|j9                  |	|t%        j:                  ||             |r:|}|d}|j9                  |
|| j                  |	| |z   | j                  || z          y y )NzQReference to inlining function other than function call in <file: %s, offset: %d>r   r   )r  None)r7   is_in_import_statement	is_calledr   r   r+   rx   r   _find_end_parensr   rb   r>  rP   rA  r@  rf   rh   r   r   r   get_primary_and_pynamerl   get_inner_scope_for_linerT  r  r  rg   rj   ry   fix_indentation)r<   rX  r   r   ri   
end_parensr`   rm   r   
line_startline_endr  r   r
  r-   hostrl   
definitionr6  r:   s                       r   occurred_outside_skipz9_InlineFunctionCallsForModuleHandle.occurred_outside_skip$  sO   113
s,,.##%---040B0BE/JK  88TXX%5C**4;;a@
++E2#}}::JJ6R
HZZ..z:
::**84 KK
5)//1R7 >{{:h/5572= 	 ))$**jA$;;=}}

33F;#~~<<KKj)OO  =  

H (Q,DKK 01##[88WM	
 D|''Ju-4t{{:c7RR	 r0   c                 T    t        j                  |      }|j                  |      d   S )Nr   )r   r5   get_word_parens_range)r<   r   r,   r   s       r   r^  z4_InlineFunctionCallsForModuleHandle._find_end_parensV  s&    v&++F3A66r0   c                 L    | j                   j                  | j                        S r@   )r*   get_pymoduler+   rF   s    r   rP   z,_InlineFunctionCallsForModuleHandle.pymoduleZ  s     ||((77r0   c                 z    | j                   | j                   j                         S | j                  j                  S r@   )r+   r6   rP   rk   rF   s    r   r   z*_InlineFunctionCallsForModuleHandle.source_  s1     ==$==%%''==,,,r0   c                 .    | j                   j                  S r@   )rP   rb   rF   s    r   rb   z)_InlineFunctionCallsForModuleHandle.linesg  s     }}"""r0   r@   )rH   rI   rJ   r>   rY  rg  r^  propertyr   saveitrP   r   rb   rA   r0   r   r{   r{     sw    
0d7 
\\8  8 
\\-  - 
\\#  #r0   r{   c                 N   t        ||      }t        ||      \  }}	t        j                  | |||      }
t	        j
                  |
||dd|      }||j                  }|rCt        j                  |      }|d |j                  |       ||j                  |	      dz   d  z   }|S |}|S )N)r   TF)rP   r   writesr8   r   )r   _assigned_linenor   rR   r   r   rk   r   r=  rf   rh   )r*   rP   r-   r:   rr   r8   r   rf  r   ri   rS   changed_sourcerb   r   s                 r   r   r   m  s     Hf-J!(F3JE3#11'4dS,,N !--..~>8U11%89U//4q8:;< 	 M  Mr0   c                 Z   |j                   d   }| j                  }t        | |      \  }}t        t	        ||dz         D cg c]  }|j                  |       c}      }|j                  rt        j                  d      ||j                  d      dz   d  j                         }|S c c}w )Nr   r   z Cannot inline tuple assignments.=)r   rb   rr  r   r   r   levelsr   r   r   r   )	rP   r-   
assignmentrb   r   ri   r   definition_with_assignmentrf  s	            r   r   r     s    ##A&JNNE!(F3JE3!,$)%q$9:q	:" ))*LMM+"((-13eg   	;s   B(c                 ~    |j                   d   j                  j                  }| j                  j	                  |      S r   )r   ast_noder`   rA  r@  )rP   r-   definition_lines      r   rr  rr    s5    ((+44;;O!!11/BBr0   c                 4   |s|S t        j                  | ||      }t        j                  | |      }|D ]  }|j	                  |        |j                         }t        j                  | ||      }t        j                  |       }|j                  |dd      S )NF)unusedsort)r   r  r   get_module_imports
add_importget_changed_sourceImportToolsorganize_imports)r*   r   r+   r]   rP   module_importimport_infoimport_toolss           r   r~   r~     s    ))'68DH227HEM .  -.--/F))'68DH**73L((%e(LLr0   c                     | j                  |      }t        j                  ||      }t        |t        j
                        r|j                         }|S r@   )rk  r   eval_locationr    r   r!   r"   )r*   r+   r,   rP   r-   s        r   r   r     sG    ##H-H##Hf5F&'../,,.Mr0   c                     t        j                  | ||      }t        j                  | |      }|j	                  |       |j                         S r@   )r   r  r   r  remove_pynamer  )r*   r-   r   r+   rP   r  s         r   r   r     sE    ))'68DH227HEM'++--r0   )TNF)+rL  typingr   rope.base.builtinsr  	rope.baser   r   r   r   r   r	   r
   r   r   rope.base.changer   r   rope.refactorr   r   r   r   r   r   r   r   r/   r2   r)   r$   r&   r   r   r   rT   r{   r   r   rr  r~   r   r   rA   r0   r   <module>r     s   & 
  
 
 
 7  34@ @"L8 L^VX Vrh <tCy S * *"S# S#lY# Y#z EJ8C

M.r0   