ó
Ù>k[c           @   sz  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l j j Z d  d l	 j j
 j Z d  d l m Z m Z m Z m Z m Z m
 Z
 d  d l m Z d  d l m Z m Z m Z y d  d l Z Wn e k
 rì d  d l Z n Xd e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d „  Z d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d „  Z" d „  Z# d S(   iÿÿÿÿN(   t
   exceptionst
   taskhandlet   prefst   historyt   pycoret   utils(   t   ModuleNotFoundError(   t   Filet   Foldert   _ResourceMatchert   _Projectc           B   s  e  Z d  „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e j ƒ  d „ Z e d	 „ Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z e e j d „  ƒ ƒ Z e e j d „  ƒ ƒ Z d „  Z d Z RS(   c         C   s=   g  |  _  | |  _ t j ƒ  |  _ t |  ƒ |  _ g  |  _ d  S(   N(   t	   observerst
   fscommandsR   t   Prefst
   _DataFilest
   data_filest   _custom_source_folders(   t   selfR   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   __init__   s
    		c         C   sŒ   |  j  | ƒ } t j j | ƒ s7 t j d | ƒ ‚ nQ t j j | ƒ rV t |  | ƒ St j j | ƒ ru t	 |  | ƒ St j d | ƒ ‚ d S(   s§  Get a resource in a project.

        `resource_name` is the path of a resource in a project.  It is
        the path of a resource relative to project root.  Project root
        folder address is an empty string.  If the resource does not
        exist a `exceptions.ResourceNotFound` exception would be
        raised.  Use `get_file()` and `get_folder()` when you need to
        get nonexistent `Resource`\s.

        s   Resource <%s> does not exists   Unknown resource N(
   t   _get_resource_patht   ost   patht   existsR    t   ResourceNotFoundErrort   isfileR   t   isdirR   (   R   t   resource_nameR   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_resource   s    	c         C   sc   |  j  j | ƒ } | d k	 r" | S|  j | | ƒ } | d k rS t d | ƒ ‚ n  |  j  j | ƒ S(   s-   Returns a `PyObject` if the module was found.s   Module %s not foundN(   R   t   builtin_modulet   Nonet   find_moduleR   t   resource_to_pyobject(   R   t   namet   foldert   pymodt   module(    (    s0   lib/python2.7/site-packages/rope/base/project.pyt
   get_module3   s    c         C   sk   g  } x^ |  j  j d g  ƒ t j D]@ } y# t ƒ  j | ƒ } | j | ƒ Wq# t j k
 rb q# Xq# W| S(   Nt   python_path(	   R   t   gett   sysR   t   get_no_projectR   t   appendR    R   (   R   t   resultt   srct
   src_folder(    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_python_path_folders>   s    #c         C   sB   |  j  d k r g  St |  j ƒ } | j |  j j |  j  ƒ ƒ | S(   s   Returns project source foldersN(   t   rootR   t   listR   t   extendR   t   _find_source_folders(   R   R*   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_source_foldersM   s
    c         C   s+   x$ t  |  j ƒ D] } | j | ƒ q Wd S(   s»   Validate files and folders contained in this folder

        It validates all of the files and folders contained in this
        folder if some observers are interested in them.

        N(   R/   R   t   validate(   R   R!   t   observer(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR3   U   s    c         C   s   |  j  j | ƒ d S(   sO   Register a `ResourceObserver`

        See `FilteredResourceObserver`.
        N(   R   R)   (   R   R4   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   add_observer_   s    c         C   s&   | |  j  k r" |  j  j | ƒ n  d S(   s&   Remove a registered `ResourceObserver`N(   R   t   remove(   R   R4   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   remove_observerf   s    c         C   s   |  j  j | d | ƒd S(   s’   Apply the changes in a `ChangeSet`

        Most of the time you call this function for committing the
        changes for a refactoring.
        t   task_handleN(   R   t   do(   R   t   changesR8   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR9   k   s    c         C   s   |  j  j | | ƒ S(   N(   R   R   (   R   t   resourcet   force_errors(    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_pymodules   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt
   get_pycorev   s    c         C   s   t  |  | ƒ S(   s+   Get the file with `path` (it may not exist)(   R   (   R   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_filey   s    c         C   s   t  |  | ƒ S(   s-   Get the folder with `path` (it may not exist)(   R   (   R   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt
   get_folder}   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt	   get_prefs   s    c         C   sD   |  j  | | | ƒ } | d  k r4 t d | ƒ ‚ n  |  j j | ƒ S(   Ns   Module %s not found(   t   find_relative_moduleR   R   R   R   (   R   R    R!   t   levelR#   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_relative_module„   s    c         C   sž   x3 |  j  ƒ  D]% } t | | ƒ } | d k	 r | Sq Wx3 |  j ƒ  D]% } t | | ƒ } | d k	 rC | SqC W| d k	 rš t | | ƒ } | d k	 rš | Sn  d S(   sj   Returns a resource corresponding to the given module

        returns None if it can not be found
        N(   R2   t   _find_module_in_folderR   R-   (   R   t   modnameR!   R+   R#   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   Š   s    c         C   sE   x! t  | d ƒ D] } | j } q W| d k r4 | St | | ƒ Sd  S(   Ni   t    (   t   ranget   parentRE   (   R   RF   R!   RC   t   i(    (    s0   lib/python2.7/site-packages/rope/base/project.pyRB      s
    c         C   s   t  S(   N(   t   False(   R   R;   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt
   is_ignored¥   s    c         C   s   d  S(   N(    (   R   R    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   ¨   s    c         C   s   t  j |  ƒ S(   N(   R   t   History(   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   «   s    c         C   s   t  j |  ƒ S(   N(   R   t   PyCore(   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   °   s    c         C   s   t  j d t d d ƒd  S(   Ns   Cannot close a NoProjectt
   stackleveli   (   t   warningst   warnt   DeprecationWarning(   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   closeµ   s    	N(    t   __name__t
   __module__R   R   R   R$   R-   R2   R3   R5   R7   R   t   NullTaskHandleR9   RK   R=   R>   R?   R@   RA   RD   R   RB   RL   R   t   propertyR   t   saveitR   R   RS   t
   ropefolder(    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR
      s2   					
											t   Projectc           B   sÚ   e  Z d  Z d d d „ Z e j d ƒ d „  ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z d d „ Z e d „  ƒ Z e d „  ƒ Z RS(   s&   A Project containing files and folderss   .ropeprojectc         K   s0  | d k r$ t  | ƒ j d ƒ } n  | |  _ | |  _ t j j |  j ƒ s^ t j |  j ƒ n' t j j |  j ƒ s… t	 j
 d ƒ ‚ n  | d k r¬ t j j j |  j ƒ } n  t t |  ƒ j | ƒ t ƒ  |  _ t |  ƒ |  _ |  j j d |  j j ƒ | d k	 r| g |  j d <n  |  j | ƒ |  j ƒ  d S(   s&  A rope project

        :parameters:
            - `projectroot`: The address of the root folder of the project
            - `fscommands`: Implements the file system operations used
              by rope; have a look at `rope.base.fscommands`
            - `ropefolder`: The name of the folder in which rope stores
              project configurations and data.  Pass `None` for not using
              such a folder at all.
            - `prefs`: Specify project preferences.  These values
              overwrite config file preferences.

        t   /s   /\s*   Project root exists and is not a directoryt   ignored_resourcesN(   t	   _realpatht   rstript   _addresst   _ropefolder_nameR   R   R   t   mkdirR   R    t	   RopeErrorR   t   ropet   baseR   t   create_fscommandst   superRZ   R   R	   t   ignoredt   _FileListCachert	   file_listR   t   add_callbackt   set_patternst   _init_prefst   _init_source_folders(   R   t   projectrootR   RY   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   ¿   s$    		s)   Delete once deprecated functions are gonec         C   sC   x< |  j  j d g  ƒ D]% } |  j | ƒ } |  j j | ƒ q Wd  S(   Nt   source_folders(   R   R&   R   R   R)   (   R   R   R!   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRm   â   s    c         C   s   |  j  j ƒ  S(   N(   Ri   t	   get_files(   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRp   è   s    c         C   s/   g  |  j  ƒ  D] } |  j j | ƒ r | ^ q S(   s1   Returns all python files available in the project(   Rp   R   t   is_python_file(   R   R;   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   get_python_filesë   s    c         C   s   t  j j |  j | j d ƒ Œ S(   NR[   (   R   R   t   joinR_   t   split(   R   R    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   ð   s    c         C   sr   |  j  d  k	 rn |  j  j ƒ  s1 |  j |  j  ƒ n  |  j  j d ƒ sn |  j  j d ƒ } | j |  j ƒ  ƒ qn n  d  S(   Ns	   config.py(   RY   R   R   t   _create_recursivelyt	   has_childt   create_filet   writet   _default_config(   R   t   config(    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   _init_ropefolderó   s    c         C   sC   | j  |  j k r5 | j  j ƒ  r5 |  j | j  ƒ n  | j ƒ  d  S(   N(   RI   R.   R   Ru   t   create(   R   R!   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRu   û   s    "c         B   s  i  } |  j  d  k	 r¸ |  j |  j  j d ƒ } | j i d d 6e d 6| j d 6ƒ | j ƒ  r‡ |  j  j d ƒ } e	 j
 | j | ƒ n |  j ƒ  | Ud | k r¸ | d |  j ƒ q¸ n  x' | j ƒ  D] \ } } | |  j | <qÅ W|  j ƒ  |  j ƒ  d | k r| d |  ƒ n  d  S(	   Ns
   /config.pyt   __main__RT   t   __builtins__t   __file__s	   config.pyt	   set_prefst   project_opened(   RY   R   R?   R   t   updateR~   t	   real_pathR   t	   get_childt   pycompatt   execfileRy   R   t   itemst   _init_other_partsR{   (   R   R   t   run_globalsRz   t   keyt   value(    (    s0   lib/python2.7/site-packages/rope/base/project.pyRl      s$    

c         C   s+   d d  l  } d d  l } | j | j j ƒ S(   Niÿÿÿÿ(   t   rope.base.default_configt   inspectt	   getsourceRd   t   default_config(   R   Rc   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRy     s    c         C   s   |  j  d  S(   N(   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRˆ     s    c         C   s   |  j  j | ƒ S(   N(   Rg   t
   does_match(   R   R;   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRL     s    c         C   s   |  j  ƒ  d S(   s   Closes project open resourcesN(   RS   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   sync!  s    c         C   s   |  j  j ƒ  d S(   s   Closes project open resourcesN(   R   Rx   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRS   %  s    c         C   s   |  j  j | | ƒ d S(   s#   Set the `key` preference to `value`N(   R   t   set(   R   RŠ   R‹   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR’   )  s    c         C   s#   |  j  d  k	 r |  j |  j  ƒ Sd  S(   N(   R`   R   R@   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRY   -  s    c         C   s2   | d  k r |  j } n  t t |  ƒ j | ƒ d  S(   N(   R   R.   Rf   RZ   R3   (   R   R!   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR3   2  s    c         C   s   |  j  d ƒ S(   NRG   (   R   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   <lambda>7  RG   c         C   s   |  j  S(   N(   R_   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR“   8  RG   N(   RT   RU   t   __doc__R   R   R   t
   deprecatedRm   Rp   Rr   R   R{   Ru   Rl   Ry   Rˆ   RL   R‘   RS   R’   RW   RY   R3   R.   t   address(    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRZ   ¼   s(   "												t	   NoProjectc           B   sA   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d Z	 RS(   sv   A null object for holding out of project files.

    This class is singleton use `get_no_project` global function
    c         C   s,   t  j j j ƒ  } t t |  ƒ j | ƒ d  S(   N(   Rc   Rd   R   t   FileSystemCommandsRf   R—   R   (   R   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   A  s    c         C   s"   | j  d t j j ƒ } t | ƒ S(   NR[   (   t   replaceR   R   t   sepR]   (   R   R    t	   real_name(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   E  s    c         C   s4   t  | ƒ j t j j d ƒ } t t |  ƒ j | ƒ S(   NR[   (   R]   R™   R   R   Rš   Rf   R—   R   (   R   R    t   universal_name(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   I  s    c         C   s   g  S(   N(    (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRp   M  s    c         C   s   g  S(   N(    (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRr   P  s    N(
   RT   RU   R”   R   R   R   Rp   Rr   R   t   _no_project(    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR—   ;  s   					c           C   s%   t  j d  k r t  ƒ  t  _ n  t  j S(   N(   R—   R   R   (    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR(   V  s    Rh   c           B   s8   e  Z d  „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C   sP   | |  _  d  |  _ t j |  j |  j |  j |  j |  j ƒ } |  j  j | ƒ d  S(   N(   t   projectR   t   filest   resourceobservert   ResourceObservert   _changedt   _invalidR5   (   R   Rž   t   rawobserver(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   ^  s    		c         C   s8   |  j  d  k r1 t ƒ  |  _  |  j |  j j ƒ n  |  j  S(   N(   RŸ   R   R’   t
   _add_filesRž   R.   (   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRp   f  s    c         C   s\   xU | j  ƒ  D]G } | j ƒ  r/ |  j | ƒ q |  j j | ƒ s |  j j | ƒ q q Wd  S(   N(   t   get_childrent	   is_folderR¥   Rž   RL   RŸ   t   add(   R   R!   t   child(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR¥   l  s
    c         C   s   | j  ƒ  r d  |  _ n  d  S(   N(   R§   R   RŸ   (   R   R;   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR¢   s  s    c         C   s   d  |  _ d  S(   N(   R   RŸ   (   R   R;   t   new_resource(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR£   w  s    N(   RT   RU   R   Rp   R¥   R¢   R   R£   (    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRh   \  s
   				R   c           B   sb   e  Z d  „  Z e e d „ Z e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(	   c         C   s   | |  _  g  |  _ d  S(   N(   Rž   t   hooks(   R   Rž   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   }  s    	c         C   s  |  j  j d  k r d  S| o% |  j ƒ  } |  j | ƒ } |  j | | ƒ } | rf | rf |  j | ƒ n  | j ƒ  r
| | j d ƒ } zu g  } y' x  t	 r² | j
 t j | ƒ ƒ q“ WWn t k
 rÇ n Xt | ƒ d k râ | d St | ƒ d k rø | SWd  | j ƒ  Xn  d  S(   Nt   rbi   i    (   Rž   RY   R   t   _can_compresst   _get_openert	   _get_filet   _import_old_filesR   Rƒ   t   TrueR)   t   picklet   loadt   EOFErrort   lenRS   (   R   R    t   compresst   import_t   openert   filet   inputR*   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt	   read_data  s*    	c         C   sƒ   |  j  j d  k	 r | o! |  j ƒ  } |  j | | ƒ } |  j | ƒ } | | j d ƒ } z t j | | d ƒ Wd  | j	 ƒ  Xn  d  S(   Nt   wbi   (
   Rž   RY   R   R­   R¯   R®   Rƒ   R²   t   dumpRS   (   R   R    t   dataR¶   R¹   R¸   t   output(    (    s0   lib/python2.7/site-packages/rope/base/project.pyt
   write_data™  s    c         C   s   |  j  j | ƒ d  S(   N(   R«   R)   (   R   t   hook(    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   add_write_hook¤  s    c         C   s   x |  j  D] } | ƒ  q
 Wd  S(   N(   R«   (   R   RÁ   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyRx   §  s    c         C   s-   y d d  l  } t SWn t k
 r( t SXd  S(   Niÿÿÿÿ(   t   gzipR±   t   ImportErrorRK   (   R   RÃ   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR­   «  s
    c         C   s^   |  j  | d t ƒ } |  j  | t ƒ } | j ƒ  rZ | j ƒ  rZ t j | j | j ƒ n  d  S(   Ns   .pickle(   R¯   RK   R   t   shutilt   moveRƒ   (   R   R    t   oldt   new(    (    s0   lib/python2.7/site-packages/rope/base/project.pyR°   ²  s    c         C   s8   | r4 y d d  l  } | j SWq4 t k
 r0 q4 Xn  t S(   Niÿÿÿÿ(   RÃ   t   openRÄ   (   R   R¶   RÃ   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR®   ¸  s    c         C   s:   |  j  j j d | } | r* | d 7} n  |  j  j | ƒ S(   NR[   s   .gz(   Rž   RY   R   R?   (   R   R    R¶   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR¯   Á  s    (   RT   RU   R   RK   R»   RÀ   RÂ   Rx   R­   R°   R®   R¯   (    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR   {  s   							c         C   s–   t  j d k rn |  d d !d k r& |  S|  d d !d k rR d |  d |  d }  n  t j j t j j |  ƒ ƒ St j j t j j t j j |  ƒ ƒ ƒ S(	   s^  Return the real path of `path`

    Is equivalent to ``realpath(abspath(expanduser(path)))``.

    Of the particular notice is the hack dealing with the unfortunate
    sitaution of running native-Windows python (os.name == 'nt') inside
    of Cygwin (abspath starts with '/'), which apparently normal
    os.path.realpath completely messes up.

    t   cygwini   i   s   :\s   :/s
   /cygdrive/i    i   (   R'   t   platformR   R   t   abspatht
   expandusert   realpath(   R   (    (    s0   lib/python2.7/site-packages/rope/base/project.pyR]   È  s    c         C   sõ   |  } | j  d ƒ } xC | d  D]7 } | j ƒ  rS | j | ƒ rS | j | ƒ } q  d  Sq  W| j ƒ  rñ | j | d ƒ r¤ | j | d ƒ j ƒ  r¤ | j | d ƒ S| j | d d ƒ rñ | j | d d ƒ j ƒ  rñ | j | d d ƒ Sn  d  S(   Nt   .iÿÿÿÿs   .py(   Rt   R§   Rv   R„   R   (   R!   RF   R#   t   packagest   pkg(    (    s0   lib/python2.7/site-packages/rope/base/project.pyRE   Ý  s    ($   R   RÅ   R'   RP   t   rope.base.fscommandsRc   t   rope.base.resourceobserverRd   R    t   rope.base.utils.pycompatR   R…   t	   rope.baseR    R   R   R   R   t   rope.base.exceptionsR   t   rope.base.resourcesR   R   R	   t   cPickleR²   RÄ   t   objectR
   RZ   R—   R(   Rh   R   R]   RE   (    (    (    s0   lib/python2.7/site-packages/rope/base/project.pyt   <module>   s*   .©	M	