ó
†Å•Zc           @   sÂ   d  d l  Z d  d l Z d  d l Z d  d l m Z m Z m Z d  d l m	 Z	 d  d l
 m Z e d e e j ƒ  d „ Z d e j ƒ  d „ Z d d d „ Z d	 e f d
 „  ƒ  YZ d „  Z d S(   iÿÿÿÿN(   t
   taskhandlet
   exceptionst   worder(   t	   fixsyntax(   t   occurrencesc      
      s»   t  j | | ƒ } |  j | ƒ } t j j j | | ƒ \ }	 }
 ‡  f d †  } t j |  | |
 d | d | d |	 ƒ} | d k r |  j
 ƒ  } n  | j d d t | ƒ ƒ} t | | | ƒ S(   sQ  Return a list of `Location`\s

    If `unsure` is `True`, possible matches are returned, too.  You
    can use `Location.unsure` to see which are unsure occurrences.
    `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.

    c            s   ˆ  S(   N(    (   t
   occurrence(   t   unsure(    s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   is_match   s    R   t   in_hierarchyt   instances   Finding Occurrencest   countN(   R   t   get_name_att   get_pymodulet   ropet   baset   evaluatet   eval_location2R   t   create_findert   Nonet   get_python_filest   create_jobsett   lent   _find_locations(   t   projectt   resourcet   offsetR   t	   resourcesR   t   task_handlet   namet   this_pymodulet   primaryt   pynameR   t   findert   job_set(    (   R   s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   find_occurrences	   s    c            s1  t  j | | ƒ } |  j | ƒ } t j j j | | ƒ ‰  ˆ  d	 k	 r‘ ˆ  j ƒ  } t	 | t j j
 j ƒ s| | j ƒ  d k r  t j d ƒ ‚ q  n t j d ƒ ‚ d „  } ‡  f d †  }	 | |	 t j ˆ  t ƒ g }
 t j |  | d |
 ƒ} | d	 k r|  j ƒ  } n  | j d d t | ƒ ƒ} t | | | ƒ S(
   s†   Find the places a given method is overridden.

    Finds the places a method is implemented.  Returns a list of
    `Location`\s.
    t   methods   Not a method!s   Cannot resolve the identifier!c         S   s   |  j  ƒ  s t Sd  S(   N(   t
   is_definedt   False(   R   (    (    s2   lib/python2.7/site-packages/rope/contrib/findit.pyR$   8   s    c            s&   |  j  ƒ  j ƒ  ˆ  j ƒ  k r" t Sd  S(   N(   t
   get_pynamet
   get_objectR%   (   R   (   R   (    s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   not_self<   s    t   filterss   Finding ImplementationsR
   N(   R   R   R   R   R   R   t   eval_locationR   R'   t
   isinstancet	   pyobjectst
   PyFunctiont   get_kindR   t   BadIdentifierErrorR   t   InHierarchyFiltert   Truet   FinderR   R   R   R   (   R   R   R   R   R   R   R   t   pyobjectR$   R(   R)   R    R!   (    (   R   s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   find_implementations&   s&    	i   c            sè   t  j |  | | | ƒ } | j | ƒ } | d k	 rä | j ƒ  \ } } t j j j | ƒ j	 | ƒ }	 | d k	 rä | j
 j | ƒ ‰  ‡  f d †  }
 t j | ƒ } t j |  |	 |
 | g ƒ } x$ | j d | ƒ D] } t | ƒ SWqä n  d S(   s¹   Return the definition location of the python name at `offset`

    A `Location` object is returned if the definition location can be
    determined, otherwise ``None`` is returned.
    c            s   |  j  ˆ  k  r t Sd  S(   N(   R   R%   (   R   (   t   start(    s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   check_offsetW   s    t   pymoduleN(   R   t	   FixSyntaxt	   pyname_atR   t   get_definition_locationR   R   R   t   Wordert   get_word_att   linest   get_line_startR   t   PyNameFilterR2   R"   t   Location(   R   t   codeR   R   t   maxfixest   fixerR   t   modulet   linenoR   R6   t   pyname_filterR    R   (    (   R5   s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   find_definitionI   s    R@   c           B   s   e  Z d  „  Z RS(   c         C   sJ   | j  |  _  | j ƒ  |  _ |  j d |  _ | j ƒ  |  _ | j |  _ d  S(   Ni    (   R   t   get_word_ranget   regionR   t	   is_unsureR   RE   (   t   selfR   (    (    s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   __init__c   s
    (   t   __name__t
   __module__RL   (    (    (    s2   lib/python2.7/site-packages/rope/contrib/findit.pyR@   a   s   c         C   sb   g  } xU | D]M } | j  | j ƒ x* |  j | ƒ D] } | j t | ƒ ƒ q3 W| j ƒ  q W| S(   N(   t   started_jobt   pathR"   t   appendR@   t   finished_job(   R    R   R!   t   resultR   R   (    (    s2   lib/python2.7/site-packages/rope/contrib/findit.pyR   k   s    (   t   rope.base.codeanalyzeR   t   rope.base.evaluatet   rope.base.pyobjectst	   rope.baseR    R   R   t   rope.contribR   t   rope.refactorR   R%   R   t   NullTaskHandleR"   R4   RG   t   objectR@   R   (    (    (    s2   lib/python2.7/site-packages/rope/contrib/findit.pyt   <module>   s   "
