
    Æe                     T    d dl Z d dlmZmZmZmZmZmZ d dlm	Z	m
Z
mZ  G d d      Zy)    N)changecodeanalyzeevaluate
exceptionslibutils	pyobjects)occurrencesrenamesourceutilsc                   8    e Zd Zd Zd Zd	dZd Zd Zd Zd Z	y)
MethodObjectc                    || _         | j                   j                  |      }t        j                  ||      }|(t	        |j                         t        j                        st        j                  d      |j                         | _
        | j                  j                         | _        | j                  j                         | _        y )NzPReplace method with method object refactoring should be performed on a function.)projectget_pymoduler   eval_location
isinstance
get_objectr   
PyFunctionr   RefactoringError
pyfunction
get_modulepymoduleget_resourceresource)selfr   r   offsetthis_pymodulepynames         =/usr/lib/python3/dist-packages/rope/refactor/method_object.py__init__zMethodObject.__init__   s    11(;''v>>F,=,=,?AUAU!V--+  !++-224224    c                    t        j                  | j                         t        j                  | j                        dz        }dj                  || j                         dt        j                  | j                        z  |      S )N   z-class {}(object):

{}{}def __call__(self):
{} )r   fix_indentation	_get_body
get_indentr   format	_get_init)r   namebodys      r   get_new_classzMethodObject.get_new_class   so    **NNk44T\\BQF
 BHHNN+((66	
 	
r!   Nc                 Z   |t        j                  dt        d       |}t        j                  | j
                  j                        }t        j                  | j                        \  }}t        j                  | j
                  j                  | j                  j                         j                               t        j                  | j                        z   }d|z  dj!                  |dj#                  | j%                                     z   }|j'                  |||       | j)                         }|j'                  ||d| j+                  |      z          t-        j.                  d      }	|	j'                  t-        j0                  | j2                  |j5                                      |	S )	Nz5new_class_name parameter is deprecated; use classnamer#   )
stacklevelr$   zreturn {}({})()
z, z

z-Replace method with method object refactoring)warningswarnDeprecationWarningr   ChangeCollectorr   source_coder   get_body_regionr   get_indentslines	get_scope	get_startr'   r   r(   join_get_parameter_names
add_change_get_class_insertion_pointr,   r   	ChangeSetChangeContentsr   get_changed)
r   	classnamenew_class_name	collectorstartendindentsnew_contents	insertionchangess
             r   get_changeszMethodObject.get_changes    sd   %MMG"
 'I//0I0IJ	 00A
s))MM!:!:!<!F!F!H
""4<<01 W}':'A'AIId//12(
 
 	UC6335	y&4+=+=i+H"H	
 ""#RS!!$--1F1F1HI	
 r!   c                 r   | j                   }|j                  | j                  k7  r&|j                  }|j                  | j                  k7  r&| j                  j                  j	                  |j                         j                               }t        |dz   t        | j                  j                              S )N   )
r   parentr   r6   get_line_endr7   get_endminlenr3   )r   currentrD   s      r   r<   z'MethodObject._get_class_insertion_point<   s    //nn-nnG nn-mm!!..w/@/@/B/J/J/LM37C 9 9:;;r!   c                    t        j                  | j                        }| j                         D ]  }|dz   |z   }t	        j
                  | j                  || j                        }||   }t        j                  | j                  ||      }t        j                  |d|z   |      }||j                  d      dz   d  } |S )Nz = None
self.)r   
rK   )r   get_bodyr   r:   r   get_string_moduler   r   r	   create_finderr
   rename_in_moduleindex)r   r+   parampymodr   finderresults          r   r&   zMethodObject._get_bodyC   s    ##DOO4..0 	4E;&-D..t||T4==QE5\F ..t||UFKF,,VWu_uUF&,,t,q023D	4 r!   c                     | j                         }dt        j                  | j                        z  }|sy|dz   }d}|D ]%  }|}|dk(  rd}|d|z  z  }||dz  d| d	| d
z   z  }' |dz  }| d
| d
S )Nr$    zdef __init__(selfr   hostz, %sr#   rS   z = rT   z):)r:   r   r'   r   )r   paramsrE   headerr+   argnew_names          r   r)   zMethodObject._get_initN   s    **,..t||<<.. 	?CHf}!fx''FGaKE#c(2">>>D	? 	$D6$$r!   c                 6    | j                   j                         S )N)r   get_param_names)r   s    r   r:   z!MethodObject._get_parameter_names^   s    ..00r!   )NN)
__name__
__module____qualname__r    r,   rI   r<   r&   r)   r:    r!   r   r   r      s%    5	
8<	% 1r!   r   )r/   	rope.baser   r   r   r   r   r   rope.refactorr	   r
   r   r   rj   r!   r   <module>rm      s      T T : :X1 X1r!   