
    Æe2                         d dl Z d dlZd dlZd dlZd dlZ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mZmZmZ  G d d      Z G d d      Z G d d      Zd	 Z G d
 d      Zy)    N)builtins
exceptionspyobjectsdefstdmods
taskhandleutilsc                      e Zd Zd Zd Zd Zd Zed        Zd*dZ	d Z
 ej                  d	      d*d
       Zd Zd Z ej                  d      d        Z ej                  d      d+d       Z ej                  d      d*d       Zd*dZ ej                  d      d        Z ej                  d      d*d       Z ej                  d      d        Z ej                  d      d        Zd,dZ ej                  d      d        Zd Zd  Zd-d!Zd" d# dfd$Zej>                  fd%Z d& Z! ej                  d'      d(        Z"eejF                  d)               Z$y).PyCorec                 0   || _         | j                          g | _        t        |       | _        t        |       | _        t        j                  j                  j                  j                  |      | _        | j                          | j                          y N)project_init_resource_observercache_observers_ModuleCachemodule_cache_ExtensionCacheextension_cacheropebaseoi
objectinfoObjectInfoManagerobject_info_init_python_files_init_automatic_soa)selfr   s     2/usr/lib/python3/dist-packages/rope/base/pycore.py__init__zPyCore.__init__   sp    $$&!(..t499<<22DDWM!  "    c                     d | _         | j                  j                  j                  dd       }|It        j
                  j                  j                         | _         | j                   j                  |       y y )Npython_files)	python_matcherr   prefsgetr   r   	resources_ResourceMatcherset_patterns)r   patternss     r   r   zPyCore._init_python_files   s`    "<<%%)).$?"&))"5"5"F"F"HD,,X6  r   c                    | j                   }t        j                  j                  j	                  |||      }t        j                  j                  j                  |      | _        | j                  j                  | j                         y N)changedmovedremoved)	_invalidate_resource_cacher   r   resourceobserverResourceObserverFilteredResourceObserverobserverr   add_observerr   callbackr2   s      r   r   zPyCore._init_resource_observer!   sg    2299-->>Hh ? 
 		22KKHU!!$--0r   c                     | j                   sy | j                  }t        j                  j                  j                  |||      }| j                  j                  |       y r*   )automatic_soa_file_changed_for_soar   r   r/   r0   r   r3   r4   s      r   r   zPyCore._init_automatic_soa)   sS    !!--99-->>Hh ? 
 	!!(+r   c                     | j                   j                  j                  dd       }| j                   j                  j                  d|      S )Nautomatic_soir7   )r   r#   r$   )r   auto_soas     r   r7   zPyCore.automatic_soa2   s;    <<%%))/4@||!!%%ox@@r   Nc                     | j                   j                  j                  |      }|t        | j                   ||       y y r   )r   historycontents_before_current_changeperform_soa_on_changed_scopes)r   resourcenew_resourceold_contentss       r   r8   zPyCore._file_changed_for_soa7   s7    ||++JJ8T#)$,,,O $r   c                     |j                         ry| j                  |j                  j                  d      S | j                  j	                  |      S )NF.py)	is_folderr"   nameendswith
does_matchr   r@   s     r   is_python_filezPyCore.is_python_file<   sI    &==))%00""--h77r   z Use `project.get_module` insteadc                 :    | j                   j                  ||      S )z-Returns a `PyObject` if the module was found.)r   
get_module)r   rF   folders      r   rL   zPyCore.get_moduleC   s     ||&&tV44r   c                     i }| j                   D ]A  }|j                  |dz         s|t        |      dz   d  }d|vs.| j                  |      ||<   C |S )N.   )extension_modules
startswithlenbuiltin_module)r   modnameresult	extensionrF   s        r   _builtin_submoduleszPyCore._builtin_submodulesH   sh    // 	BI##GcM2 W!1!34d?#'#6#6y#AF4L		B
 r   c                 8    | j                   j                  |      S r   )r   get_pymodule)r   rF   s     r   rT   zPyCore.builtin_moduleQ   s    ##0066r   z)Use `project.get_relative_module` insteadc                 <    | j                   j                  |||      S r   )r   get_relative_module)r   rF   rM   levels       r   r\   zPyCore.get_relative_moduleT   s    ||//feDDr   z(Use `libutils.get_string_module` insteadc                 4    t        j                  | |||      S )zReturns a `PyObject` object for the given code

        If `force_errors` is `True`, `exceptions.ModuleSyntaxError` is
        raised if module has syntax errors.  This overrides
        ``ignore_syntax_errors`` project config.

        force_errors)r   PyModule)r   coder@   r`   s       r   get_string_modulezPyCore.get_string_moduleX   s     $$T4UUr   z'Use `libutils.get_string_scope` insteadc                 V    t         j                  j                  j                  ||      S )z+Returns a `Scope` object for the given code)r   r   libutilsget_string_scope)r   rb   r@   s      r   rf   zPyCore.get_string_scopec   s!     yy!!224BBr   c                 6    | j                   D ]
  } ||        y r   )r   )r   r@   rA   r2   s       r   r.   z!PyCore._invalidate_resource_cacheh   s    ,, 	HX	r   z-Use `project.get_python_path_folders` insteadc                 6    | j                   j                         S r   )r   get_python_path_foldersr   s    r   ri   zPyCore.get_python_path_foldersl   s    ||3355r   z!Use `project.find_module` insteadc                 :    | j                   j                  ||      S )zjReturns a resource corresponding to the given module

        returns None if it can not be found
        )r   find_module)r   rU   rM   s      r   rl   zPyCore.find_modulep   s     ||''88r   z*Use `project.find_relative_module` insteadc                 <    | j                   j                  |||      S r   )r   find_relative_module)r   rU   rM   r]   s       r   rn   zPyCore.find_relative_modulex   s    ||00&%HHr   z(Use `project.get_source_folders` insteadc                 6    | j                   j                         S )zReturns project source folders)r   get_source_foldersrj   s    r   rp   zPyCore.get_source_folders   s     ||..00r   c                 :    | j                   j                  ||      S r   )r   rZ   )r   r@   r`   s      r   resource_to_pyobjectzPyCore.resource_to_pyobject   s      --hEEr   z&Use `project.get_python_files` insteadc                 6    | j                   j                         S )z1Returns all python files available in the project)r   get_python_filesrj   s    r   rt   zPyCore.get_python_files   s     ||,,..r   c                 h    |j                  d      xr  |j                  d      j                          S )Nz__init__.py)	has_child	get_childrE   )r   rM   s     r   _is_packagezPyCore._is_package   s5    ]+ @$$]3==??	
r   c                 P   |j                         D ]  }| j                  |      s|gc S  g }|j                         D ]0  }|j                  j	                  d      s|j                  |        n |j                         D ]"  }|j                  | j                  |             $ |S )NrD   )get_foldersrx   	get_filesrF   rG   appendextend_find_source_folders)r   rM   r@   rV   s       r   r~   zPyCore._find_source_folders   s    **, 	 H)x	  ((* 	H}}%%e,f%	 **, 	?HMM$33H=>	?r   c                    | j                   j                  j                  dd      }| j                   j                  j                  d|      }| j                  j                  }|sd}t
        j                  j                  j                  j                  | |||||      }|j                  | j                  j                         |j                          |S )zRun `resource` module

        Returns a `rope.base.oi.doa.PythonFileRunner` object for
        controlling the process.

        perform_doiTperform_doaN)r   r#   r$   r   doa_data_receivedr   r   r   doaPythonFileRunneradd_finishing_observerr   forget_all_datarun)r   r@   argsstdinstdoutr   receiverrunners           r   
run_modulezPyCore.run_module   s     ll((,,]DAll((,,]KH##55H!!22(D%
 	%%d&7&7&G&GH

r   c                      yNT pys    r   <lambda>zPyCore.<lambda>       r   c                      yr   r   r   s    r   r   zPyCore.<lambda>   r   r   c                    |&| j                   j                  j                  dd      }| j                  |      }| j                  j                          t        j                  j                  j                  j                  | ||||       y)a  Analyze `resource` module for static object inference

        This function forces rope to analyze this module to collect
        information about function calls.  `should_analyze` is a
        function that is called with a `PyDefinedObject` argument.  If
        it returns `True` the element is analyzed.  If it is `None` or
        returns `False` the element is not analyzed.

        `search_subscopes` is like `should_analyze`; The difference is
        that if it returns `False` the sub-scopes are all ignored.
        That is it is assumed that `should_analyze` returns `False`
        for all of its subscopes.

        `followed_calls` override the value of ``soa_followed_calls``
        project config.
        Nsoa_followed_callsr   )r   r#   r$   rr   r   r   r   r   r   soaanalyze_module)r   r@   should_analyzesearch_subscopesfollowed_callspymodules         r   r   zPyCore.analyze_module   sq    . !!\\//334H!LN,,X6))+		''(N,<n	
r   c                 >    t        j                  dt        d       g S )Nz$`PyCore.get_classes()` is deprecated   )
stacklevel)warningswarnDeprecationWarning)r   task_handles     r   get_classeszPyCore.get_classes   s    24FST	
 	r   c                 X    t        | j                        t        | j                        z   S r   )strr   r   rj   s    r   __str__zPyCore.__str__   s#    4$$%D,<,<(===r   zUse `libutils.modname` insteadc                 T    t         j                  j                  j                  |      S r   )r   r   re   rU   rI   s     r   rU   zPyCore.modname   s    yy!!))(33r   c                     t        | j                  j                  j                  dg             }| j                  j                  j                  dd      r#|j	                  t        j                                |S )NrQ   import_dynload_stdmodsF)setr   r#   r$   updater   dynload_modules)r   rV   s     r   rQ   zPyCore.extension_modules   s[     T\\''++,?DE<<!!":EBMM'1134r   r   )NFF)NNN)%__name__
__module____qualname__r   r   r   r   propertyr7   r8   rJ   r   
deprecatedrL   rX   rT   r\   rc   rf   r.   ri   rl   rn   rp   rr   rt   rx   r~   r   r   r   DEFAULT_TASK_HANDLEr   r   rU   cacheitrQ   r   r   r   r
   r
      s   #71, A AP
8 U895 :57 UABE CE U@AV BV U?@C AC UEF6 G6 U9:9 ;9 UBCI DI U@A1 B1F U>?/ @/
, '(
> '1&D&D > U674 84 
]]  r   r
   c                   ,    e Zd Zd Zd ZddZd Zd Zy)r   c                     || _         i | _        | j                   j                  j                  | j                         | j                   j
                  | _        y r   )pycore
module_mapr   r|   _invalidate_resourcer2   r   r   s     r   r   z_ModuleCache.__init__   s?    ##**4+D+DE,,r   c                     || j                   v r9| j                          | j                  j                  |       | j                   |= y y r   )r   r   r2   remove_resourcerI   s     r   r   z!_ModuleCache._invalidate_resource   s=    t&  "MM))(3) 'r   c                 Z   || j                   v r| j                   |   S |j                         r#t        j                  | j                  ||      }n0t        j
                  | j                  ||      }|j                  r|S || j                   |<   | j                  j                  |       |S )Nr_   )r@   r`   )	r   rE   r   	PyPackager   ra   
has_errorsr2   add_resource)r   r@   r`   rV   s       r   rZ   z_ModuleCache.get_pymodule   s    t&??8,,!++)F "**!)F
   $*!""8,r   c                 b    | j                   j                         D ]  }|j                           y r   )r   values_forget_concluded_data)r   r   s     r   r   z_ModuleCache.forget_all_data  s*    ..0 	.H++-	.r   c                 2    dt        | j                        z  S )NzPyCore caches %d PyModules
)rS   r   rj   s    r   r   z_ModuleCache.__str__  s    -DOO0DDDr   Nr   )r   r   r   r   r   rZ   r   r   r   r   r   r   r      s    -**.Er   r   c                       e Zd Zd Zd Zy)r   c                      || _         i | _        y r   )r   
extensionsr   s     r   r   z_ExtensionCache.__init__  s    r   c                    |dk(  rt         j                   S | j                  j                  }|| j                  vr1||v r-t        j                  || j                        | j                  |<   | j                  j                  |      S )N__builtin__)r   r   rQ   r   BuiltinModuler$   )r   rF   alloweds      r   rZ   z_ExtensionCache.get_pymodule  sk    = $$$++//t&47?$,$:$:4$MDOOD!""4((r   N)r   r   r   r   rZ   r   r   r   r   r     s    )r   r   c                 F   | j                   }|j                         rx|j                  |      rft        j                  t
        j                        5  |j                         }t        ||      fd}fd}|j                  |||       d d d        y y y # 1 sw Y   y xY w)Nc                     | j                         }j                  |j                         |j                               S r   )	get_scope
is_changed	get_startget_end)	pydefinedscopedetectors     r   r   z7perform_soa_on_changed_scopes.<locals>.search_subscopes)  s1    !++-**5??+<emmoNNr   c                     | j                         }|j                         }|j                         }j                  ||      S r   )r   r   r   consume_changes)r   r   startendr   s       r   r   z5perform_soa_on_changed_scopes.<locals>.should_analyze-  s;    !++-)mmo//s;;r   )
r   existsrJ   
contextlibsuppressr   ModuleSyntaxErrorread_TextChangeDetectorr   )r   r@   rB   r   new_contentsr   r   r   s          @r   r?   r?   !  s    ^^FV228<  !=!=> 	N#==?L*<FHO< !!(N<LM	N 	N =	N 	Ns   :BB c                   *    e Zd Zd Zd Zd Zd Zd Zy)r   c                 @    || _         || _        | j                          y r   )oldnew
_set_diffs)r   r   r   s      r   r   z_TextChangeDetector.__init__7  s    r   c                 b   t        j                         }g | _        d}|j                  | j                  j                  d      | j                  j                  d            D ]K  }|j                  d      r|dz  }|j                  d      s,|dz  }| j                  j                  |       M y )Nr   T rP   -)	difflibDifferlinescomparer   
splitlinesr   rR   r|   )r   differlinenolines       r   r   z_TextChangeDetector._set_diffs<  s    !
NNHH%txx':':4'@
 	*D s#!%!

!!&)	*r   c                 6    | j                  ||      \  }}||k  S )z~Tell whether any of start till end lines have changed

        The end points are inclusive and indices start from 1.
        )_get_changedr   r   r   leftrights        r   r   z_TextChangeDetector.is_changedI  s$    
 ''s3ee|r   c                 ^    | j                  ||      \  }}||k  r| j                  ||= ||k  S )z5Clear the changed status of lines from start till end)r   r   r   s        r   r   z#_TextChangeDetector.consume_changesQ  s9    ''s3e%<

4:&e|r   c                     t        j                  | j                  |      }t        j                  | j                  |      }||fS r   )bisectbisect_leftr   bisect_rightr   s        r   r   z _TextChangeDetector._get_changedX  s8    !!$**e4##DJJ4U{r   N)r   r   r   r   r   r   r   r   r   r   r   r   r   6  s    
*r   r   )r   r   r   r   rope.base.libutilsr   rope.base.oi.doarope.base.oi.objectinforope.base.oi.soarope.base.resourceobserverrope.base.resources	rope.baser   r   r   r   r   r   r
   r   r   r?   r   r   r   r   <module>r     s]            !  T TW Wt'E 'ET) )N*% %r   