
ŕZc           @   s@  d  Z  d d l m Z m Z m Z m Z m Z m Z m Z m	 Z	 d d l
 m Z m Z m Z d d l m Z m Z m Z m Z m Z d d  Z d e f d     YZ d e f d	     YZ d
 e f d     YZ d e f d     YZ d e f d     YZ d   Z d   Z d e f d     YZ d e f d     YZ d S(   s   A module containing classes for move refactoring

`create_move()` is a factory for creating move refactoring objects
based on inputs.

i(   t	   pyobjectst   codeanalyzet
   exceptionst   pynamest
   taskhandlet   evaluatet   wordert   libutils(   t	   ChangeSett   ChangeContentst   MoveResource(   t   importutilst   renamet   occurrencest   sourceutilst   functionutilsc         C   s  | d k r t |  |  S|  j |  } t j | |  } | d k	 r| j   } t | t j  sv t | t j	  r t |  | j
    St | t j  r t | j t j  r t |  | |  St | t j  r t | j t j  s t | t j  rt |  | |  Sn  t j d   d S(   s   A factory for creating Move objects

    Based on `resource` and `offset`, return one of `MoveModule`,
    `MoveGlobal` or `MoveMethod` for performing move refactoring.

    sK   Move only works on global classes/functions/variables, modules and methods.N(   t   Nonet
   MoveModulet   get_pymoduleR   t   eval_locationt
   get_objectt
   isinstanceR    t   PyModulet	   PyPackaget   get_resourcet
   PyFunctiont   parentt   PyClasst
   MoveMethodt   PyDefinedObjectR   t   AssignedNamet
   MoveGlobalR   t   RefactoringError(   t   projectt   resourcet   offsett   this_pymodulet   pynamet   pyobject(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   create_move   s$    R   c           B   s   e  Z d  Z d   Z d d e j   d  Z d   Z d   Z	 d   Z
 d   Z d   Z d   Z d	   Z d
 d  Z d   Z d   Z d   Z d   Z RS(   s   For moving methods

    It makes a new method in the destination class and changes
    the body of the old method to call the new method.  You can
    inline the old method to change all of its occurrences.

    c         C   s|   | |  _  |  j  j |  } t j | |  } t j | |  |  _ | j   |  _ |  j j	   d k rx t
 j d   n  d  S(   Nt   methods!   Only normal methods can be moved.(   R!   R   R   R   R   t   get_name_att   method_nameR   t
   pyfunctiont   get_kindR   R    (   t   selfR!   R"   R#   R$   R%   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   __init__3   s    	c         C   s  t  d |  j  } | d k r1 |  j j   } n  | d k rL |  j   } n  |  j | |  \ } } } }	 t j | j	    }
 |
 j
 | | |	  |  j | |  \ } } } } | | k r |
 j
 | | |  n t j | j	    } | j
 | | |  | j   } t j |  j  } |  j |  } | rZt j |  j | |  } t | | |  } n  | | k r| j
 t | |   n  | | k r| j
 t | |
 j     n  | S(   s  Return the changes needed for this refactoring

        Parameters:

        - `dest_attr`: the name of the destination attribute
        - `new_name`: the name of the new method; if `None` uses
          the old name
        - `resources` can be a list of `rope.base.resources.File`\s to
          apply this refactoring on.  If `None`, the restructuring
          will be applied to all python files.

        s   Moving method <%s>N(   R   R*   R   R!   t   get_python_filest   get_method_namet   _get_changes_made_by_old_classR   t   ChangeCollectort   readt
   add_changet   _get_changes_made_by_new_classt   get_changedR   t   ImportToolst   _get_used_importsR   t   get_string_modulet   _add_imports_to_moduleR	   (   R-   t	   dest_attrt   new_namet	   resourcest   task_handlet   changest	   resource1t   start1t   end1t   new_content1t
   collector1t	   resource2t   start2t   end2t   new_content2t
   collector2t   resultt   import_toolst   new_importst   goal_pymodule(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   get_changes=   s6    c         C   s   |  j  S(   N(   R*   (   R-   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR0   l   s    c         C   s   t  j |  j |  j  S(   N(   R   t   get_importsR!   R+   (   R-   RK   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR8   o   s    c         C   sv   |  j  j   } |  j |  j   } d | | |  j   f } t j |  j   } | j   | d | d t j | |  f S(   Ns   return self.%s.%s(%s)
i    i   (   R+   t
   get_modulet   _get_scope_indentst   _get_passed_arguments_stringR   t   get_body_regionR   t   fix_indentation(   R-   R;   R<   t   pymodulet   indentst   bodyt   region(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR1   r   s    c         C   s;   | j    } t j | j | j   j    t j |  j  S(   N(   RP   R   t   get_indentst   linest	   get_scopet	   get_startt
   get_indentR!   (   R-   R&   RU   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRQ   {   s    c         C   s  |  j  j } | | k r. t j d |   n  | | j   j   } t | t j  sl t j d |   n  | j	   } | j	   j
   } t j |  \ } } d }	 | j | | !j   d k r d }	 | } n  |  j |  }
 |	 t j |  j |  |
  } | | | | f S(   Ns$   Destination attribute <%s> not founds%   Unknown class type for attribute <%s>s   
t   passs   

(   R+   R   R   R    R   t   get_typeR   R    R   RP   R   R   RS   t   source_codet   stripRQ   RT   t   get_new_method(   R-   R;   R<   t   old_pyclasst   pyclassRU   R"   t   startt   endt
   pre_blanksRV   RW   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR5      s&    		c         C   s5   d |  j  |  t j |  j   t j |  j   f S(   Ns   %s
%s(   t   _get_new_headerR   RT   t	   _get_bodyR]   R!   (   R-   t   name(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRb      s    c         C   s   t  j |  j  S(   N(   R   t   get_bodyR+   (   R-   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   _get_unchanged_body   s    t   hostc         C   s   |  j    } | d |  j   } t j |  j |  } t j |  j | | |  } t j | | d | } | d  k r~ | } n  | | j
 d  d S(   Ns    = None
RU   s   
i   (   t   _get_self_nameRl   R   R9   R!   R   t   create_finderR   t   rename_in_moduleR   t   index(   R-   Rm   t	   self_nameRW   RU   t   finderRJ   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRi      s    	c         C   s   |  j  j   d S(   Ni    (   R+   t   get_param_names(   R-   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRn      s    c         C   sf   d | } |  j    r# | d 7} n  t j j |  j  } | j d  } | r^ | d | 7} n  | d S(   Ns   def %s(selfs   , hosti   s   , s   ):(   t   _is_host_usedR   t   DefinitionInfoR3   R+   t   arguments_to_string(   R-   Rj   t   headert   definition_infot   others(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRh      s    
c         C   si   d } |  j    r d } n  t j j |  j  } | j d  } | re | rX | d 7} n  | | 7} n  | S(   Nt    R-   i   s   , (   Ru   R   Rv   R3   R+   Rw   (   R-   RJ   Ry   Rz   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRR      s    	c         C   s   |  j  d  |  j   k S(   Nt
   __old_self(   Ri   Rl   (   R-   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRu      s    N(   t   __name__t
   __module__t   __doc__R.   R   R   t   NullTaskHandleRN   R0   R8   R1   RQ   R5   Rb   Rl   Ri   Rn   Rh   RR   Ru   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   *   s    	
.										
	R   c           B   s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d e
 j   d  Z d   Z d	   Z d
   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s&   For moving global function and classesc         C   s   | |  _  |  j  j |  } t j | |  |  _ |  j d  k rQ t j d   n  |  j |  j  r t	 j
 | |  |  _ | } n- |  j j   j   |  _ |  j j   j   } |  j   | j   |  _ t |  j  |  j |  j |  j  |  _ |  j j |  _ d  S(   NsB   Move refactoring should be performed on a class/function/variable.(   R!   R   R   R   t
   old_pynameR   R   R    t   _is_variableR   R)   t   old_nameR   t   get_nameRP   t   _check_exceptional_conditionsR   t   sourcet
   _MoveToolst   toolsRK   (   R-   R!   R"   R#   R$   RU   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR.      s     		
c            s   t  j |  j   t | j t j  rG t  f d   | j j D  St | j t j	  r d  k r  j
 d d  \ }   | j j | k r t   f d   | j j D  r t Sn  | j j  k St S(   Nc         3   s!   |  ] \ } }   | k Vq d  S(   N(    (   t   .0Rj   t   alias(   t   module_name(    s1   lib/python2.7/site-packages/rope/refactor/move.pys	   <genexpr>   s   t   .i   c         3   s!   |  ] \ } }   | k Vq d  S(   N(    (   R   Rj   R   (   t   basename(    s1   lib/python2.7/site-packages/rope/refactor/move.pys	   <genexpr>   s   (   R   t   modnameR   R   t   import_infoR   t   NormalImportt   anyt   names_and_aliasest
   FromImportt   rsplitR   t   Truet   False(   R-   t   stmtt   package_name(    (   R   R   s1   lib/python2.7/site-packages/rope/refactor/move.pyt   _import_filter   s    c         C   s   |  j  |  j  rc |  j j   d } y | j   j |  j  Wq t j k
 r_ |  j   q Xn@ t	 |  j j
   t j  o |  j |  j j
    s |  j   n  d  S(   Ni    (   R   R   t   get_definition_locationR[   R   R   R   t   NameNotFoundErrort   _raise_refactoring_errorR   R   R    R   t
   _is_global(   R-   RU   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR      s    c         C   s   t  j d   d  S(   NsM   Move refactoring should be performed on a global class, function or variable.(   R   R    (   R-   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR      s    c         C   s   | j    j | j   j    k S(   N(   R[   R   RP   (   R-   R&   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c         C   s   t  | t j  S(   N(   R   R   R   (   R-   R%   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c         C   s   | d  k r |  j j   } n  | d  k s7 | j   rI t j d   n  | j   rv | j d  rv | j d  } n  | j   r t j d   n  |  j	 | k r t j d   n  |  j
 | | |  S(   Ns    Move destination does not exist.s   __init__.pys7   Move destination for non-modules should not be folders.s*   Moving global elements to the same module.(   R   R!   R/   t   existsR   R    t	   is_foldert	   has_childt	   get_childR   t   _calculate_changes(   R-   t   destR=   R>   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRN     s    c         C   s  t  d |  j  } | j d t |   } x| D]} | j | j  | |  j k rp | j |  j |   nS| | k r | j |  j	 |   n.|  j
 j d |  r|  j j |  } d |  j } |  j
 j | d | }	 |	 d  k	 }
 |  j
 j | |	  } |  j j | d t d |  j }	 |
 r|  j
 j | |	  } t j |  j | |  j |  |  j  \ }	 } |	 j | |  }	 n  |  j
 j | |	  }	 |	 | j   k r| j t | |	   qn  | j   q2 W| S(   Ns   Moving global <%s>s   Collecting ChangesR"   s   __rope_renaming_%s_t   sortt   import_filter(   R   R   t   create_jobsett   lent   started_jobt   pathR   R4   t   _source_module_changest   _dest_module_changesR   t   occurs_in_moduleR!   R   Rp   R   t   new_pymoduleRK   t   organize_importsR   R   R   t
   add_importt   _new_modnamet   replacet
   new_sourceR3   R	   t   finished_job(   R-   R   R=   R>   R?   t   job_sett   file_RU   t   placeholderR   t   should_importt   imported(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s:    			c         C   s  d |  j  } t |  } t j |  j |  j  |  j  } |  j   \ } } t | |  j | | |  } | j	   } t
 j |  j | |  j  }	 |  j j |	 d t } | j r	t
 j |  j | |  j  }	 t j |  j |	 |  j |  |  j   \ } }
 | j | |
  } n  t |  j |  S(   Ns   __rope_moving_%s_R   (   R   t   _ChangeMoveOccurrencesHandleR   Ro   R!   R   t   _get_moving_regiont   ModuleSkipRenamerR   t   get_changed_moduleR   R9   RK   R   R   t   occurredR   R   R   R   R	   (   R-   R   R   t   handlet   occurrence_finderRe   Rf   t   renamerR   RU   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   :  s"    	'c         C   s   t  j |  S(   N(   R   R   (   R-   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   N  s    c      
   C   s  |  j  j |  } |  j j |  j |  } |  j j | |  } |  j   \ } } |  j | |  \ } } |  j j	 |  } | j
 } d } | j r | j d j d } nK xH | | j j   k  r | j j | d  j   j d  r | d 7} q W| d k r4| j j |  d }	 | |	  d | | |	 }
 n
 | | }
 |
 } t j |  j  | |  } |  j j | d t d t } t j |  j  | |  } |  j j | d t d t d t d	 |  j } t | |  S(
   Ni    ii   t   #s   

R   t   unusedt   selfsR   (   R!   R   R   Rp   R   R   t    _get_moving_element_with_importst   _add_imports2RK   t   module_importsR`   t   importst   end_lineRZ   t   lengtht   get_linet   lstript
   startswitht   get_line_endR   R9   R   R   R   R   R	   (   R-   R   RU   R   t   movingR   t   has_changedt   module_with_importst   linenot   cutRJ   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   Q  s6    			
		c         C   s   t  |  j |  j |  j    S(   N(   t   moving_code_with_importsR!   R   t   _get_moving_element(   R-   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   v  s    c         C   s(   t  j |  j | |  } |  j j |  S(   N(   R   R9   R!   RK   R   (   R-   R`   R"   RU   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   _get_module_with_importsz  s    c         C   s6   |  j    \ } } |  j j   | | !} | j   d S(   Ns   
(   R   R   R3   t   rstrip(   R-   Re   Rf   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c   
      C   s|  |  j  j |  j  } | j } |  j |  j  r~ | j } | j |  j j   d  d } | j	 |  } | j |  d } n6 |  j j
   j   } | j	 | j    } | j   } | j |  } x6 | d k r | j | d  j d  r | d 8} q W| j	 |  } x? | | j   k  rL| j | d  j   d k rL| d 7} qWt | j |  d t | j   }	 | |	 f S(   Ni   i    R   R{   (   R!   R   R   RZ   R   R   t   logical_linest   logical_line_inR   t   get_line_startR   R[   R\   t   get_endt   get_line_numberR   R   R   Ra   t   minR   R   R`   (
   R-   RU   RZ   R   R   Re   R   t   scopet
   start_lineRf   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s(    		+%c         C   s]   |  j  j | |  } | d  k r+ | t f S| j   } t j |  j | |  } | t f Sd  S(   N(	   R   t   add_importsR   R   R   R   R9   R!   R   (   R-   RU   RL   R   R"   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    
N(   R}   R~   R   R.   R   R   R   R   R   R   R   R   RN   R   R   R   R   R   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR      s$   							"			%				R   c           B   sq   e  Z d  Z d   Z d
 e j   d  Z d   Z d   Z	 d   Z
 d   Z d
 d
 d  Z d   Z d	   Z RS(   s   For moving modules and packagesc         C   s  | |  _  | j   r1 | j d k r1 | j } n  | j   r_ | j d  r_ t j d   n  t j |  j  d  } t	 j
 | d | |  _ |  j j   j   |  _ |  j j   r |  j j |  _ n |  j j d  |  _ t |  j  |  j |  j |  j  |  _ |  j j |  _ d  S(   Ns   __init__.pys   Cannot move non-package folder.R{   R"   i(   R!   R   Rj   R   R   R   R    R   R9   R   t   ImportedModuleR   R   R   R   R   R   R   RK   (   R-   R!   R"   t   dummy_pymodule(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR.     s     	c         C   s\   | d  k r |  j j   } n  | d  k s7 | j   rI t j d   n  |  j | | |  S(   Ns0   Move destination for modules should be packages.(   R   R!   R/   R   R   R    R   (   R-   R   R=   R>   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRN     s    c         C   s   t  d |  j  } | j d t |   } x | D]| } | j | j  | |  j k rj |  j | |  n: |  j | d | } | d  k	 r | j
 t | |   n  | j   q2 W|  j |  j j k r | j
 t |  j | j   n  | S(   Ns   Moving module <%s>s   Collecting changesR"   (   R   R   R   R   R   R   R   t   _change_moving_modulet   _change_occurrences_in_moduleR   R4   R	   R   R!   R
   (   R-   R   R=   R>   R?   R   t   moduleR   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    		c         C   s+   t  j |  } | r$ | d |  j S|  j S(   NR   (   R   R   R   (   R-   R   t   destname(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c         C   s   t  j |  j |  d  f g  S(   N(   R   R   R   R   (   R-   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   _new_import  s    c         C   s   |  j  j   s |  j j |  j   } |  j j |  } |  j j | |  } |  j | |  } |  j j	 | |  } | |  j  j
   k r | j t |  j  |   q n  d  S(   N(   R   R   R!   R   RK   t   relatives_to_absolutesR   R   R   R   R3   R4   R	   (   R-   R?   R   RU   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c   
      C   s  |  j  j d | d |  s d  S| d  k r@ |  j j |  } n  |  j |  } t j |  j |  } t } d  } t	 j
 |  r |  j | | |  } | r | j   } |  j  j | |  } |  j  j | |  } q n  |  j |  } |  j  j | d t d | d | s| n d  } |  j  j d | d | d t  }	 |  j  j | |  } |  j  j |  } |	 r|  j  j | |  } |  j  j | | g  } n  |  j  j | |  } | d  k	 r| | j j   k r| Sd  S(   NRU   R"   R   (   R   R   R   R!   R   R   R   t   get_module_importsR   R   R   t   _change_import_statementst   get_changed_sourceR   R   R   Rp   R   t   remove_old_importsR   R"   R3   (
   R-   R   RU   R"   R<   R   t   changedR   t
   new_importR   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s>    			!c   	         s"    j  } | j } t } x| j D] } t   f d   | j j D  rt t   f d   | j j D  rt q" n  t | j t j	  r q" n    j
 | | | |  p | } t j j   j d   } | j j   r" | j j |  | k r" t j | | j j | j j  | _ t } q" q" W| S(   Nc         3   s"   |  ] } | d    j  k Vq d S(   i    N(   R   (   R   t   name_and_alias(   R-   (    s1   lib/python2.7/site-packages/rope/refactor/move.pys	   <genexpr>  s   c         3   s+   |  ]! } | d  t  j   j  k Vq d S(   i    N(   R   R   R   (   R   R   (   R-   (    s1   lib/python2.7/site-packages/rope/refactor/move.pys	   <genexpr>  s   (   R   R   R   R   R   R   R   R   R   R   t"   _handle_moving_in_from_import_stmtt
   importinfot   ImportContextR!   R   t   is_emptyt   get_imported_resourceR   t   levelR   (	   R-   R   R<   R   t   moving_modulet   parent_moduleR   t   import_stmtt   context(    (   R-   s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s,    			c         C   s  t  } t j j |  j d   } | j j |  | k r| j j } g  } xv | D]n \ }	 }
 |	 |  j	 k r t
 } t j t j |  d |  j	 |
 f g  } | j |  qO | j |	 |
 f  qO W| | k rt
 } | r t j | j j | j j |  | _ q| j   qn  | S(   Ni    (   R   R   R   R   R!   R   R   R   R   R   R   R   R   R   R   t   appendR   R   t   empty_import(   R-   R   R   R   R   R   R   R   RL   Rj   R   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   2  s.    			N(   R}   R~   R   R.   R   R   R   RN   R   R   R   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s   					
"	"R   c           B   s#   e  Z d    Z d   Z d   Z RS(   c         C   s   | |  _  t |  _ d  S(   N(   R<   R   R   (   R-   R<   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR.   T  s    	c         C   s   d  S(   N(    (   R-   t   change_collectort
   occurrence(    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   occurred_inside_skipX  s    c         C   s5   | j    \ } } | j | | |  j  t |  _ d  S(   N(   t   get_primary_rangeR4   R<   R   R   (   R-   R   R   Re   Rf   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   occurred_outside_skip[  s    (   R}   R~   R.   R   R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   R  s   		R   c           B   sb   e  Z d    Z d   Z d e d d  Z d d e d  Z d   Z	 d   Z
 d   Z d   Z RS(	   c         C   s=   | |  _  | |  _ | |  _ | |  _ t j |  j   |  _ d  S(   N(   R!   R   R   R   R   R7   RK   (   R-   R!   R   R%   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR.   c  s
    				c            sp     j  }  j j    } d t f    f d     Y} |   } | j |  | j   } | | k rl | Sd  S(   Nt	   CanSelectc              s/   e  Z e Z  j Z  j Z   f d    Z RS(   c            sZ   y? | |  j  k r>   | j   |  j j   k r> t |  _ t SWn t j k
 rU n Xt S(   N(   R   R   R   R   R   R   R   t   AttributeNotFoundError(   R-   Rj   (   RU   (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   __call__s  s    	(   R}   R~   R   R   R   R   R  (    (   RU   R-   (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   n  s   		(   R`   RK   R   t   objectt   filter_namesR   (   R-   RU   t
   old_sourceR   R   t
   can_selectR   (    (   RU   R-   s1   lib/python2.7/site-packages/rope/refactor/move.pyR   j  s    		c      	   C   s7   |  j  |  } t j | | d t d | d | } | S(   Nt   replace_primaryRU   R"   (   t   _create_finderR   Rp   R   (   R-   R<   RU   R   R"   R   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyRp     s
    c         C   s7   |  j  |  } x! | j d | d |  D] } t SWt S(   NRU   R"   (   R  t   find_occurrencesR   R   (   R-   RU   R"   R   Rs   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s
    c         C   s(   t  j |  j |  j |  j d | d t S(   NR   t   keywords(   R   Ro   R!   R   R   R   (   R-   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR    s    c         C   s,   | d  k	 r( t j |  j | | j    S| S(   N(   R   R   R9   R!   R   (   R-   RU   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c         C   s   | d  k r | j S| S(   N(   R   R`   (   R-   RU   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c         C   s   t  |  j | |  S(   N(   R:   RK   (   R-   RU   RL   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    N(   R}   R~   R.   R   R   R   Rp   R   R   R  R   R   R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR   a  s   					c         C   s7   |  j  |  } x | D] } | j |  q W| j   S(   N(   R   R   R   (   RK   RU   RL   R   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR:     s    c         C   se  t  j |   } t j |  | |  } t j |  } d } x8 | | j   k  rs | j |  j d  rs | d 7} q< W| | j	 |   } t j |  | | j	 |  |  } |  j
 |  } g  }	 x* | j |  j D] }
 |	 j |
 j  q Wg  } x* | D]" } | | k r | j |  q q W|	 j | j | |   t | | |	  } t j |  | |  } | j |  } t j |  | |  } | j | d t } t j |  | |  } | j |  } g  | j D] } | j ^ q}	 d } | j r| j d j } n  t j |  } x6 | | j   k  rC| j |  j   rC| d 7} qW| | | j	 |  } | |	 f S(   Ni   R   R   i(   R   R7   R   R9   R   t   SourceLinesAdapterR   R   R   R   R   R   R   R   R   t   get_from_importR:   R   R   R   R   Ra   (   R!   R"   R   RK   RU   RZ   Re   t   moving_prefixt   originR   R   t
   back_namesRj   R   R   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     sF    -	+t   ModuleSkipRenamerHandlec           B   s   e  Z d    Z d   Z RS(   c         C   s   d  S(   N(    (   R-   R   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    c         C   s   d  S(   N(    (   R-   R   R   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    (   R}   R~   R   R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR    s   	R   c           B   s,   e  Z d  Z d d d d d  Z d   Z RS(   s   Rename occurrences in a module

    This class can be used when you want to treat a region in a file
    separately from other parts when renaming.

    i    R{   c         C   sX   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ |  j d k rT t   |  _ n  d S(   s   Constructor

        if replacement is `None` the region is not changed.  Otherwise
        it is replaced with `replacement`.

        N(   R   R"   t
   skip_startt   skip_endt   replacementR   R   R  (   R-   R   R"   R   R  R  R  (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR.     s    						c         C   s   |  j  j   } t j |  } |  j d  k	 rL | j |  j |  j |  j  n  xz |  j	 j
 |  j   D]c } | j   \ } } |  j | k o |  j k  n r |  j j | |  qb |  j j | |  qb W| j   } | d  k	 r | | k r | Sd  S(   N(   R"   R3   R   R2   R  R   R4   R  R  R   R	  R   R   R   R   R6   (   R-   R   R   R   Re   Rf   RJ   (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s    "N(   R}   R~   R   R   R.   R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyR     s   N(    R   t	   rope.baseR    R   R   R   R   R   R   R   t   rope.base.changeR   R	   R
   t   rope.refactorR   R   R   R   R   R   R'   R  R   R   R   R   R   R:   R   R  R   (    (    (    s1   lib/python2.7/site-packages/rope/refactor/move.pyt   <module>   s   :(E		2	