ó
†Å•Zc           @   s„  d  d l  Z  d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z d  d	 l m Z m 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 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 S(   iÿÿÿÿN(   t   codeanalyze(   t   evaluate(   t	   pyobjects(   t
   taskhandle(   t   utils(   t   worder(   t   ChangeContentst	   ChangeSet(   t   occurrencest   functionutilst   ChangeSignaturec           B   sì   e  Z d  „  Z d „  Z d d e j ƒ  d „ Z d „  Z d „  Z	 e
 j d ƒ d „  ƒ Z d „  Z e
 j ƒ  d „  ƒ Z e
 j ƒ  d	 „  ƒ Z e
 j ƒ  d d d
 „ ƒ Z e
 j ƒ  d „  ƒ Z e
 j ƒ  d „  ƒ Z e d e j ƒ  d „ Z RS(   c         C   s   | |  _  | |  _ | |  _ |  j ƒ  |  j d  k se |  j j ƒ  d  k se t |  j j ƒ  t j	 ƒ r} t
 j j j d ƒ ‚ n  d  S(   Ns8   Change method signature should be performed on functions(   t   projectt   resourcet   offsett   _set_name_and_pynamet   pynamet   Nonet
   get_objectt
   isinstanceR   t
   PyFunctiont   ropet   baset
   exceptionst   RefactoringError(   t   selfR   R   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   __init__   s    			
$c         C   s*  t  j |  j |  j ƒ |  _ |  j j |  j ƒ } t j | |  j ƒ \ |  _	 |  _
 |  j
 d  k rd d  S|  j
 j ƒ  } t | t j ƒ rª d | k rª | d |  _
 d |  _ n  |  j
 j ƒ  } d  |  _ |  j d k r&t | t j ƒ r&t | j t j ƒ r&| j } | j ƒ  | j | j ƒ  f |  _ n  d  S(   NR   (   R   t   get_name_atR   R   t   nameR   t   get_pymoduleR   t   eval_location2t   primaryR   R   R   R   R   t   PyClasst   othersR   t   parentt   get_name(   R   t   this_pymodulet   pyobjectt   pyclass(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR      s&    			c         C   sE  | d  k r |  j j ƒ  } n  t d |  j ƒ } | j d t | ƒ ƒ } t j |  j |  j |  j	 d |  j
 d | o| |  j ƒ  ƒ} |  j rÍ |  j \ } }	 t j |  j | |	 d t ƒ}
 t | |
 g ƒ } n  xq | D]i } | j | j ƒ t |  j | | | ƒ } | j ƒ  } | d  k	 r3| j t | | ƒ ƒ n  | j ƒ  qÔ W| S(   Ns   Changing signature of <%s>s   Collecting Changest   instancet   in_hierarchyt
   only_calls(   R   R   t   get_python_filesR   R   t   create_jobsett   lenR   t   create_finderR   R   t	   is_methodR    t   Truet   _MultipleFinderst   started_jobt   patht   _ChangeCallsInModulet   get_changed_modulet
   add_changeR   t   finished_job(   R   t   call_changerR'   t	   resourcest   handlet   changest   job_sett   finderR   R   t   constructor_findert   filet   change_callst   changed_file(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   _change_calls/   s*    	c         C   s   |  j  ƒ  j S(   sÐ   Get function arguments.

        Return a list of ``(name, default)`` tuples for all but star
        and double star arguments.  For arguments that don't have a
        default, `None` will be used.
        (   t   _definfot   args_with_defaults(   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   get_argsG   s    c         C   s"   |  j  j ƒ  } t | j t j ƒ S(   N(   R   R   R   R!   R   R   (   R   t
   pyfunction(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR-   P   s    s(   Use `ChangeSignature.get_args()` insteadc         C   s
   |  j  ƒ  S(   N(   RA   (   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   get_definition_infoT   s    c         C   s   t  j j |  j j ƒ  ƒ S(   N(   R	   t   DefinitionInfot   readR   R   (   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRA   X   s    c         C   s4   t  |  j j ƒ  |  j ƒ  t ƒ  g ƒ } |  j | ƒ S(   N(   t   _FunctionChangersR   R   RE   t   ArgumentNormalizerR@   (   R   t   changer(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt	   normalize[   s    c         C   s7   t  |  j j ƒ  |  j ƒ  t | ƒ g ƒ } |  j | ƒ S(   N(   RH   R   R   RE   t   ArgumentRemoverR@   (   R   t   indexRJ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   removeb   s    c         C   s@   t  |  j j ƒ  |  j ƒ  t | | | | ƒ g ƒ } |  j | ƒ S(   N(   RH   R   R   RE   t   ArgumentAdderR@   (   R   RM   R   t   defaultt   valueRJ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   addi   s    c         C   s7   t  |  j j ƒ  |  j ƒ  t | ƒ g ƒ } |  j | ƒ S(   N(   RH   R   R   RE   t   ArgumentDefaultInlinerR@   (   R   RM   RJ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   inline_defaultp   s    c         C   s7   t  |  j j ƒ  |  j ƒ  t | ƒ g ƒ } |  j | ƒ S(   N(   RH   R   R   RE   t   ArgumentReordererR@   (   R   t   new_orderingRJ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   reorderw   s    c         C   s7   t  |  j j ƒ  |  j ƒ  | ƒ } |  j | | | | ƒ S(   s  Get changes caused by this refactoring

        `changers` is a list of `_ArgumentChanger`\s.  If `in_hierarchy`
        is `True` the changers are applyed to all matching methods in
        the class hierarchy.
        `resources` can be a list of `rope.base.resource.File`\s that
        should be searched for occurrences; if `None` all python files
        in the project are searched.

        (   RH   R   R   RA   R@   (   R   t   changersR'   R7   t   task_handlet   function_changer(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   get_changes~   s    N(   t   __name__t
   __module__R   R   R   R   t   NullTaskHandleR@   RC   R-   R   t
   deprecatedRE   RA   RK   RN   RR   RT   RW   t   FalseR[   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR
      s    	
						RH   c           B   s/   e  Z d d  „ Z d „  Z d „  Z d „  Z RS(   c         C   s.   | |  _  | |  _ | |  _ |  j ƒ  |  _ d  S(   N(   RD   t   definition_infoRX   t   _get_changed_definition_infost   changed_definition_infos(   R   RD   Ra   RX   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR   ’   s    			c         C   s]   g  } |  j  } | j | ƒ x: |  j D]/ } t j | ƒ } | j | ƒ | j | ƒ q& W| S(   N(   Ra   t   appendRX   t   copyt   deepcopyt   change_definition_info(   R   t   resultRa   RJ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRb   ˜   s    	c         C   s   |  j  d j ƒ  S(   Niÿÿÿÿ(   Rc   t	   to_string(   R   t   call(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   change_definition¢   s    c         C   sƒ   t  j j | | |  j | ƒ } t  j |  j | ƒ } x3 t |  j |  j ƒ D] \ } } | j | | ƒ qI W| j	 |  j d ƒ j
 ƒ  S(   Niÿÿÿÿ(   R	   t   CallInfoRG   Ra   t   ArgumentMappingt   zipRc   RX   t   change_argument_mappingt   to_call_infoRi   (   R   R   R   Rj   t	   call_infot   mappingRa   RJ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   change_call¥   s    		N(   R\   R]   R   R   Rb   Rk   Rs   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRH      s   	
	t   _ArgumentChangerc           B   s   e  Z d  „  Z d „  Z RS(   c         C   s   d  S(   N(    (   R   Ra   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRg   µ   s    c         C   s   d  S(   N(    (   R   Ra   t   argument_mapping(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRo   ¸   s    (   R\   R]   Rg   Ro   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRt   ³   s   	RI   c           B   s   e  Z RS(    (   R\   R]   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRI   ¼   s   RL   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   RM   (   R   RM   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR   Â   s    c         C   sÛ   |  j  t | j ƒ k  r( | j |  j  =n¯ |  j  t | j ƒ k r[ | j d  k	 r[ d  | _ n| |  j  t | j ƒ k r‘ | j d  k r‘ | j d  k	 sË |  j  t | j ƒ d k r× | j d  k	 r× | j d  k	 r× d  | _ n  d  S(   Ni   (   RM   R+   RB   t   args_argR   t   keywords_arg(   R   Rq   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRg   Å   s    c         C   sH   |  j  t | j ƒ k  rD | j d } | | j k rD | j | =qD n  d  S(   Ni    (   RM   R+   RB   t
   param_dict(   R   Ra   Rr   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRo   Ó   s    (   R\   R]   R   Rg   Ro   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRL   À   s   		RO   c           B   s)   e  Z d d d  „ Z d „  Z d „  Z RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   RM   R   RP   RQ   (   R   RM   R   RP   RQ   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR   Ü   s    			c         C   sl   xC | j  D]8 } | d |  j k r
 t j j j d |  j ƒ ‚ q
 q
 W| j  j |  j |  j |  j f ƒ d  S(   Ni    s!   Adding duplicate parameter: <%s>.(	   RB   R   R   R   R   R   t   insertRM   RP   (   R   Ra   t   pair(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRg   â   s    c         C   s)   |  j  d  k	 r% |  j  | j |  j <n  d  S(   N(   RQ   R   Rx   R   (   R   Ra   Rr   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRo   ê   s    N(   R\   R]   R   R   Rg   Ro   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRO   Ú   s   	RS   c           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s   | |  _  t |  _ d  S(   N(   RM   R`   RN   (   R   RM   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR   ñ   s    	c         C   s4   |  j  r0 | j |  j d d  f | j |  j <n  d  S(   Ni    (   RN   RB   RM   R   (   R   Ra   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRg   õ   s    	c         C   sW   | j  |  j d } | j  |  j d } | d  k	 rS | | j k rS | | j | <n  d  S(   Ni   i    (   RB   RM   R   Rx   (   R   Ra   Rr   RP   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRo   ú   s    (   R\   R]   R   Rg   Ro   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRS   ï   s   		RU   c           B   s   e  Z d d  „ Z d „  Z RS(   c         C   s   | |  _  | |  _ d S(   sË  Construct an `ArgumentReorderer`

        Note that the `new_order` is a list containing the new
        position of parameters; not the position each parameter
        is going to be moved to. (changed in ``0.5m4``)

        For example changing ``f(a, b, c)`` to ``f(c, a, b)``
        requires passing ``[2, 0, 1]`` and *not* ``[1, 2, 0]``.

        The `autodef` (automatic default) argument, forces rope to use
        it as a default if a default is needed after the change.  That
        happens when an argument without default is moved after
        another that has a default value.  Note that `autodef` should
        be a string or `None`; the latter disables adding automatic
        default.

        N(   t	   new_ordert   autodef(   R   R{   R|   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR     s    	c         C   sÈ   t  | j ƒ } x. t |  j ƒ D] \ } } | j | | | <q Wt } xr t t  | ƒ ƒ D]^ \ } \ } } | d  k	 r€ t } n  | rY | d  k rY |  j d  k	 rY | |  j f | | <qY qY W| | _ d  S(   N(   t   listRB   t	   enumerateR{   R`   R   R.   R|   (   R   Ra   t   new_argst	   new_indexRM   t   seen_defaultt   argRP   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRg     s    %	!N(   R\   R]   R   R   Rg   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyRU     s   R2   c           B   sb   e  Z d  „  Z d „  Z e e j d „  ƒ ƒ Z e e j d „  ƒ ƒ Z e e j d „  ƒ ƒ Z	 RS(   c         C   s(   | |  _  | |  _ | |  _ | |  _ d  S(   N(   R   t   occurrence_finderR   R6   (   R   R   Rƒ   R   R6   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR   '  s    			c         C   s  t  j |  j ƒ } t j |  j ƒ } xé |  j j |  j ƒ D]Ò } | j ƒ  r` | j	 ƒ  r` q: n  | j
 ƒ  \ } } | j | d ƒ \ } } | j ƒ  rÎ | j ƒ  \ } }	 |  j j | |	 |  j | | !ƒ }
 n |  j j |  j | | !ƒ }
 |
 d  k	 r: | j | | |
 ƒ q: q: W| j ƒ  S(   Ni   (   R   t   Wordert   sourceR    t   ChangeCollectorRƒ   t   find_occurrencesR   t	   is_calledt
   is_definedt   get_primary_ranget   get_word_parens_ranget   get_primary_and_pynameR6   Rs   Rk   R   R4   t   get_changed(   R   t   word_findert   change_collectort
   occurrencet   startt   endt   begin_parenst
   end_parensR   R   t   changed_call(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR3   -  s$    		c         C   s   |  j  j |  j ƒ S(   N(   R   R   R   (   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   pymoduleB  s    c         C   s*   |  j  d  k	 r |  j  j ƒ  S|  j j Sd  S(   N(   R   R   RG   R–   t   source_code(   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR…   G  s    c         C   s
   |  j  j S(   N(   R–   t   lines(   R   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR˜   O  s    (
   R\   R]   R   R3   t   propertyR   t   saveitR–   R…   R˜   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR2   %  s   		R/   c           B   s    e  Z d  „  Z d d d „ Z RS(   c         C   s   | |  _  d  S(   N(   t   finders(   R   R›   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR   W  s    c         C   sJ   g  } x* |  j  D] } | j | j | | ƒ ƒ q W| j d d „  ƒ | S(   Nt   keyc         S   s
   |  j  ƒ  S(   N(   RŠ   (   t   x(    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   <lambda>^  t    (   R›   t   extendR‡   t   sort(   R   R   R–   t   all_occurrencesR;   (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR‡   Z  s
    N(   R\   R]   R   R   R‡   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyR/   U  s   	(   Re   t   rope.base.exceptionsR   t	   rope.baseR    R   R   R   R   R   t   rope.base.changeR   R   t   rope.refactorR   R	   t   objectR
   RH   Rt   RI   RL   RO   RS   RU   R2   R/   (    (    (    s=   lib/python2.7/site-packages/rope/refactor/change_signature.pyt   <module>   s&   ‚#	$0