ó
ĊZc           @   sz   d  d l  Z  d  d l m Z d  d l m Z m Z m Z m Z m Z d  d l m	 Z	 m
 Z
 m Z d e f d     YZ d S(   i˙˙˙˙N(   t   libutils(   t	   pyobjectst
   exceptionst   changet   evaluatet   codeanalyze(   t   sourceutilst   occurrencest   renamet   MethodObjectc           B   sM   e  Z d    Z d   Z d d d  Z d   Z d   Z d   Z d   Z	 RS(   c         C   s   | |  _  |  j  j |  } t j | |  } | d  k sR t | j   t j  rd t	 j
 d   n  | j   |  _ |  j j   |  _ |  j j   |  _ d  S(   NsP   Replace method with method object refactoring should be performed on a function.(   t   projectt   get_pymoduleR   t   eval_locationt   Nonet
   isinstancet
   get_objectR   t
   PyFunctionR   t   RefactoringErrort
   pyfunctiont
   get_modulet   pymodulet   get_resourcet   resource(   t   selfR
   R   t   offsett   this_pymodulet   pyname(    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyt   __init__
   s    	c         C   sR   t  j |  j   t  j |  j  d  } d | |  j   d t  j |  j  | f S(   Ni   s-   class %s(object):

%s%sdef __call__(self):
%st    (   R   t   fix_indentationt	   _get_bodyt
   get_indentR
   t	   _get_init(   R   t   namet   body(    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyt   get_new_class   s
    "c   
      C   s*  | d  k	 r+ t j d t d d | } n  t j |  j j  } t j	 |  j
  \ } } t j |  j j |  j
 j   j    t j |  j  } d | d | d j |  j    f } | j | | |  |  j   } | j | | d |  j |   t j d  }	 |	 j t j |  j | j     |	 S(	   Ns5   new_class_name parameter is deprecated; use classnamet
   stackleveli   R   s   return %s(%s)()
s   , s   

s-   Replace method with method object refactoring(   R   t   warningst   warnt   DeprecationWarningR   t   ChangeCollectorR   t   source_codeR   t   get_body_regionR   t   get_indentst   linest	   get_scopet	   get_startR   R
   t   joint   _get_parameter_namest
   add_changet   _get_class_insertion_pointR#   R   t	   ChangeSett   ChangeContentsR   t   get_changed(
   R   t	   classnamet   new_class_namet	   collectort   startt   endt   indentst   new_contentst	   insertiont   changes(    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyt   get_changes   s*    	
	c         C   si   |  j  } x | j |  j k r* | j } q W|  j j j | j   j    } t | d t |  j j	   S(   Ni   (
   R   t   parentR   R,   t   get_line_endR-   t   get_endt   mint   lenR)   (   R   t   currentR:   (    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyR2   5   s
    	!c         C   sĞ   t  j |  j  } x |  j   D] } | d | } t j |  j | |  j  } | | } t j	 |  j | |  } t
 j | d | d | } | | j d  d } q W| S(   Ns    = None
s   self.R   s   
i   (   R   t   get_bodyR   R0   R    t   get_string_moduleR
   R   R   t   create_finderR   t   rename_in_modulet   index(   R   R"   t   paramt   pymodR   t   findert   result(    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyR   <   s    
	c         C   sŞ   |  j    } d t j |  j  } | s, d S| d } d } xS | D]K } | } | d k rd d } n  | d | 7} | | d d | | f 7} qC W| d	 7} d
 | | f S(   NR   t    s   def __init__(selfR   t   hosts   , %si   s   self.%s = %s
s   ):s   %s
%s
(   R0   R   R   R
   (   R   t   paramsR;   t   headerR"   t   argt   new_name(    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyR    I   s    
	 
c         C   s   |  j  j   S(   N(   R   t   get_param_names(   R   (    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyR0   Y   s    N(
   t   __name__t
   __module__R   R#   R   R?   R2   R   R    R0   (    (    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyR	      s   					(   R%   t	   rope.baseR    R   R   R   R   R   t   rope.refactorR   R   R   t   objectR	   (    (    (    s:   lib/python2.7/site-packages/rope/refactor/method_object.pyt   <module>   s   (