ó
†Å•Zc           @   sr  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z m Z m	 Z	 d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ 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 e f d „  ƒ  YZ d „  Z d „  Z d e
 f d „  ƒ  YZ d „  Z d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d S(   iÿÿÿÿN(   t
   taskhandlet
   exceptionst   utilst   Changec           B   sP   e  Z d  Z d d „ Z d d „ Z d „  Z d „  Z e e	 j
 d „  ƒ ƒ Z RS(   s€   The base class for changes

    Rope refactorings return `Change` objects.  They can be previewed,
    committed or undone.
    c         C   s   d S(   sa   Perform the change

        .. note:: Do use this directly.  Use `Project.do()` instead.
        N(    (   t   selft   job_set(    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   do   t    c         C   s   d S(   sc   Perform the change

        .. note:: Do use this directly.  Use `History.undo()` instead.
        N(    (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   undo   R   c         C   s
   t  |  ƒ S(   sd   Return the description of this change

        This can be used for previewing the changes.
        (   t   str(   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   get_description   s    c         C   s   g  S(   s1   Return the list of resources that will be changed(    (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   get_changed_resources$   s    c         C   s   t  |  j j ƒ S(   N(   t   _ResourceOperationst   resourcet   project(   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   _operations(   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R   R
   R   t   propertyR   t   saveitR   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   
   s   		t	   ChangeSetc           B   sb   e  Z d  Z d d „ Z e j ƒ  d „ Z e j ƒ  d „ Z d „  Z	 d „  Z
 d „  Z d „  Z RS(	   sÐ   A collection of `Change` objects

    This class holds a collection of changes.  This class provides
    these fields:

    * `changes`: the list of changes
    * `description`: the goal of these changes
    c         C   s   g  |  _  | |  _ | |  _ d  S(   N(   t   changest   descriptiont   time(   R   R   t	   timestamp(    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   __init__8   s    		c         C   s}   yG g  } x+ |  j  D]  } | j | ƒ | j | ƒ q Wt j ƒ  |  _ Wn/ t k
 rx x | D] } | j ƒ  q^ W‚  n Xd  S(   N(   R   R   t   appendR   t	   ExceptionR   (   R   R   t   donet   change(    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   =   s    c         C   st   y> g  } x1 t  |  j ƒ D]  } | j | ƒ | j | ƒ q WWn/ t k
 ro x | D] } | j ƒ  qU W‚  n Xd  S(   N(   t   reversedR   R   R   R   R   (   R   R   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   I   s    c         C   s   |  j  j | ƒ d  S(   N(   R   R   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt
   add_changeT   s    c         C   sT   t  |  ƒ d g } x1 |  j D]& } | j | j ƒ  ƒ | j d ƒ q Wd j | ƒ S(   Ns   :


s   
R   (   R	   R   R   R
   t   join(   R   t   resultR   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR
   W   s
    c         C   sê   |  j  d  k	 rã t j j |  j  ƒ } | j ƒ  t j j ƒ  k rH d } nm | j ƒ  t j j ƒ  t j d ƒ k ry d } n< | j t j j ƒ  j k r¦ | j d ƒ } n | j d ƒ } | j d ƒ } d | | f } |  j	 d | S|  j	 S(	   Nt   todayi   t	   yesterdays   %b %ds	   %d %b, %Ys   %H:%M:%Ss   %s %s s    - (
   R   R   t   datetimet   fromtimestampt   dateR$   t	   timedeltat   yeart   strftimeR   (   R   R(   t   string_datet   string_time(    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   __str__^   s    		c         C   s4   t  ƒ  } x$ |  j D] } | j | j ƒ  ƒ q W| S(   N(   t   setR   t   updateR   (   R   R#   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   o   s    	N(   R   R   R   R   R   R    t
   NullJobSetR   R   R!   R
   R.   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   .   s   			c            s   t  j ƒ  ‡  f d † } | S(   s–   A decorator for handling `taskhandle.JobSet`\s

    A decorator for handling `taskhandle.JobSet`\s for `do` and `undo`
    methods of `Change`\s.
    c            s+   | j  t |  ƒ ƒ ˆ  |  ƒ | j ƒ  d  S(   N(   t   started_jobR	   t   finished_job(   R   R   (   t   function(    s/   lib/python2.7/site-packages/rope/base/change.pyt   call|   s    
(   R    R1   (   R4   R5   (    (   R4   s/   lib/python2.7/site-packages/rope/base/change.pyt   _handle_job_setv   s    t   ChangeContentsc           B   sS   e  Z d  Z d d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 RS(   s¦   A class to change the contents of a file

    Fields:

    * `resource`: The `rope.base.resources.File` to change
    * `new_contents`: What to write in the file
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   t   new_contentst   old_contents(   R   R   R8   R9   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   Œ   s    		c         C   sA   |  j  d  k r$ |  j j ƒ  |  _  n  |  j j |  j |  j ƒ d  S(   N(   R9   R   R   t   readR   t
   write_fileR8   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ’   s    c         C   s>   |  j  d  k r! t j d ƒ ‚ n  |  j j |  j |  j  ƒ d  S(   Ns+   Undoing a change that is not performed yet!(   R9   R   R   t   HistoryErrorR   R;   R   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ˜   s    c         C   s   d |  j  j S(   Ns   Change <%s>(   R   t   path(   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR.   Ÿ   s    c         C   s™   |  j  } |  j } | d  k rH |  j j ƒ  r? |  j j ƒ  } qH d } n  t j | j t	 ƒ | j t	 ƒ d |  j j
 d |  j j
 ƒ } d j t | ƒ ƒ S(   NR   s   a/s   b/(   R8   R9   R   R   t   existsR:   t   difflibt   unified_difft
   splitlinest   TrueR=   R"   t   list(   R   t   newt   oldR#   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR
   ¢   s    			 c         C   s
   |  j  g S(   N(   R   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ¯   s    N(   R   R   R   R   R   R6   R   R   R.   R
   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR7   ƒ   s   		t   MoveResourcec           B   sS   e  Z d  Z e d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z	 d „  Z
 RS(   sé   Move a resource to a new location

    Fields:

    * `resource`: The `rope.base.resources.Resource` to move
    * `new_resource`: The destination for move; It is the moved
      resource not the folder containing that resource.
    c         C   sj   | j  |  _  | |  _ | s- t | | ƒ } n  | j ƒ  rQ |  j  j | ƒ |  _ n |  j  j | ƒ |  _ d  S(   N(   R   R   t   _get_destination_for_movet	   is_foldert
   get_foldert   new_resourcet   get_file(   R   R   t   new_locationt   exact(    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ½   s    	c         C   s   |  j  j |  j |  j ƒ d  S(   N(   R   t   moveR   RJ   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   Ç   s    c         C   s   |  j  j |  j |  j ƒ d  S(   N(   R   RN   RJ   R   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   Ë   s    c         C   s   d |  j  j S(   Ns	   Move <%s>(   R   R=   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR.   Ï   s    c         C   s   d |  j  j |  j j f S(   Ns   rename from %s
rename to %s(   R   R=   RJ   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR
   Ò   s    c         C   s   |  j  |  j g S(   N(   R   RJ   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   Ö   s    (   R   R   R   t   FalseR   R6   R   R   R.   R
   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRF   ³   s   
		t   CreateResourcec           B   sY   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sX   A class to create a resource

    Fields:

    * `resource`: The resource to create
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   â   s    c         C   s   |  j  j |  j ƒ d  S(   N(   R   t   createR   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   å   s    c         C   s   |  j  j |  j ƒ d  S(   N(   R   t   removeR   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   é   s    c         C   s   d |  j  j S(   Ns   Create Resource <%s>(   R   R=   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR.   í   s    c         C   s   d |  j  j S(   Ns   new file %s(   R   R=   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR
   ð   s    c         C   s
   |  j  g S(   N(   R   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ó   s    c         C   s&   | j  d k r | S| j  d | Sd  S(   NR   t   /(   R=   (   R   t   parentt   name(    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   _get_child_pathö   s    (   R   R   R   R   R6   R   R   R.   R
   R   RV   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRP   Ú   s   				t   CreateFolderc           B   s   e  Z d  Z d „  Z RS(   sC   A class to create a folder

    See docs for `CreateResource`.
    c         C   s8   | j  j |  j | | ƒ ƒ } t t |  ƒ j | ƒ d  S(   N(   R   RI   RV   t   superRW   R   (   R   RT   RU   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR     s    	(   R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRW   ý   s   t
   CreateFilec           B   s   e  Z d  Z d „  Z RS(   sA   A class to create a file

    See docs for `CreateResource`.
    c         C   s8   | j  j |  j | | ƒ ƒ } t t |  ƒ j | ƒ d  S(   N(   R   RK   RV   RX   RY   R   (   R   RT   RU   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR     s    (   R   R   R   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRY   	  s   t   RemoveResourcec           B   sG   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z RS(   s\   A class to remove a resource

    Fields:

    * `resource`: The resource to be removed
    c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR     s    c         C   s   |  j  j |  j ƒ d  S(   N(   R   RR   R   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR     s    c         C   s   t  d ƒ ‚ d  S(   Ns0   Undoing `RemoveResource` is not implemented yet.(   t   NotImplementedError(   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   $  s    c         C   s   d |  j  j S(   Ns   Remove <%s>(   R   R=   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR.   )  s    c         C   s
   |  j  g S(   N(   R   (   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ,  s    (	   R   R   R   R   R6   R   R   R.   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRZ     s   		c         C   sA   t  |  t ƒ r= d } x! |  j D] } | t | ƒ 7} q W| Sd S(   s7   Counts the number of basic changes a `Change` will makei    i   (   t
   isinstanceR   R   t   count_changes(   R   R#   t   child(    (    s/   lib/python2.7/site-packages/rope/base/change.pyR]   0  s    c         C   s   |  j  t | ƒ t | ƒ ƒ S(   N(   t   create_jobsetR	   R]   (   t   task_handleR   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   create_job_set:  s    R   c           B   sJ   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C   s.   | |  _  | j |  _ t j j j ƒ  |  _ d  S(   N(   R   t
   fscommandst   ropet   baset   FileSystemCommandst   direct_commands(   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   @  s    	c         C   s    |  j  j | ƒ r |  j S|  j S(   N(   R   t
   is_ignoredRf   Rb   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   _get_fscommandsE  s    c         C   se   t  j j j | ƒ } |  j | ƒ } | j | j | ƒ x' t |  j j	 ƒ D] } | j
 | ƒ qJ Wd  S(   N(   Rc   Rd   Rb   t   unicode_to_file_dataRh   t   writet	   real_pathRC   R   t	   observerst   resource_changed(   R   R   t   contentst   dataRb   t   observer(    (    s/   lib/python2.7/site-packages/rope/base/change.pyR;   J  s
    c         C   sV   |  j  | ƒ } | j | j | j ƒ x* t |  j j ƒ D] } | j | | ƒ q8 Wd  S(   N(   Rh   RN   Rk   RC   R   Rl   t   resource_moved(   R   R   RJ   Rb   Rp   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRN   Q  s    c         C   sc   | j  ƒ  r% |  j | j d d ƒn |  j | j ƒ x' t |  j j ƒ D] } | j | ƒ qH Wd  S(   Nt   kindt   folder(   RH   t   _create_resourceR=   RC   R   Rl   t   resource_created(   R   R   Rp   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRQ   W  s
    c         C   sM   |  j  | ƒ } | j | j ƒ x' t |  j j ƒ D] } | j | ƒ q2 Wd  S(   N(   Rh   RR   Rk   RC   R   Rl   t   resource_removed(   R   R   Rb   Rp   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyRR   _  s    t   filec         C   sÙ   |  j  j | ƒ } t j j | ƒ r: t j d | ƒ ‚ n  |  j  j | ƒ } | j j ƒ  st t j	 d | j ƒ ‚ n  |  j
 | ƒ } y- | d k r¢ | j | ƒ n | j | ƒ Wn" t k
 rÔ } t j | ƒ ‚ n Xd  S(   Ns   Resource <%s> already existss$   Parent folder of <%s> does not existRw   (   R   t   _get_resource_patht   osR=   R>   R   t	   RopeErrorRK   RT   t   ResourceNotFoundErrorRh   t   create_filet   create_foldert   IOError(   R   t	   file_nameRr   t   resource_pathR   Rb   t   e(    (    s/   lib/python2.7/site-packages/rope/base/change.pyRt   e  s    	(	   R   R   R   Rh   R;   RN   RQ   RR   Rt   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   >  s   						c         C   sM   |  j  j | ƒ } t j j | ƒ rI | d k r? | d |  j S|  j Sn  | S(   NR   RS   (   R   Rx   Ry   R=   t   isdirRU   (   R   t   destinationt	   dest_path(    (    s/   lib/python2.7/site-packages/rope/base/change.pyRG   x  s    
t   ChangeToDatac           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sF   | j  } g  } x$ | j D] } | j |  | ƒ ƒ q W| | | j f S(   N(   R   R   R   R   (   R   R   R   R   R^   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   convertChangeSet„  s
    	c         C   s   | j  j | j | j f S(   N(   R   R=   R8   R9   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   convertChangeContents‹  s    c         C   s   | j  j | j j f S(   N(   R   R=   RJ   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   convertMoveResourceŽ  s    c         C   s   | j  j | j  j ƒ  f S(   N(   R   R=   RH   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   convertCreateResource‘  s    c         C   s   | j  j | j  j ƒ  f S(   N(   R   R=   RH   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   convertRemoveResource”  s    c         C   sP   t  | ƒ } | t t f k r' t } n  t |  d | j ƒ } | j | | ƒ f S(   Nt   convert(   t   typeRW   RY   RP   t   getattrR   (   R   R   t   change_typet   method(    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   __call__—  s
    	(   R   R   R†   R‡   Rˆ   R‰   RŠ   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR…   ‚  s   					t   DataToChangec           B   sJ   e  Z d  „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   c         C   s   | |  _  d  S(   N(   R   (   R   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   ¡  s    c         C   s7   t  | | ƒ } x! | D] } | j |  | ƒ ƒ q W| S(   N(   R   R!   (   R   R   R   R   R#   R^   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   makeChangeSet¤  s    c         C   s"   |  j  j | ƒ } t | | | ƒ S(   N(   R   RK   R7   (   R   R=   R8   R9   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   makeChangeContentsª  s    c         C   s%   |  j  j | ƒ } t | | d t ƒS(   NRM   (   R   RK   RF   RB   (   R   t   old_patht   new_pathR   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   makeMoveResource®  s    c         C   s7   | r |  j  j | ƒ } n |  j  j | ƒ } t | ƒ S(   N(   R   RI   RK   RP   (   R   R=   RH   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   makeCreateResource²  s    c         C   s7   | r |  j  j | ƒ } n |  j  j | ƒ } t | ƒ S(   N(   R   RI   RK   RZ   (   R   R=   RH   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   makeRemoveResource¹  s    c         C   s%   t  |  d | d ƒ } | | d Œ  S(   Nt   makei    i   (   R   (   R   Ro   R   (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR   À  s    N(
   R   R   R   R   R’   R“   R–   R—   R˜   R   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyR‘   Ÿ  s   					(   R&   R?   Ry   R   t   rope.base.fscommandsRc   t	   rope.baseR    R   R   t   objectR   R   R6   R7   RF   RP   RW   RY   RZ   R]   Ra   R   RG   R…   R‘   (    (    (    s/   lib/python2.7/site-packages/rope/base/change.pyt   <module>   s(   $H	0'#	
	:	
