ó
‹²,]c           @   s÷   d  Z  d d l Z d d l Z d d l Z d d l j 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 m Z m Z d d l m Z d e f d	 „  ƒ  YZ d
 „  Z d „  Z d d d d „ Z e	 d „  ƒ Z d „  Z d S(   s(   
Introspection utilities used by Spyder
iÿÿÿÿN(   t   memoize(   t   custom_extension_lexer_mapping(   t   words(   t   get_lexer_for_filenamet   get_lexer_by_namet	   TextLexer(   t   Tokent   CodeInfoc           B   st   e  Z e j d  e j ƒ Z e j d e j ƒ Z d e e d d „ Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z RS(	   s   [^\d\W][\w\.]*s   ([^\d\W][\w\.]*)\([^\)\()]*\Zc   
      K   s?  |  j  j | ƒ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | rÚ |  j	 ƒ  |  _
 | d k rã xd | rÓ |  j | | d !}	 |	 j d ƒ s« |	 j d ƒ rÆ | |	 j d ƒ d 7} Pn  | d 8} qs Wqã n	 d |  _
 | |  _ | d k r1g  |  _ d |  _ d |  _ d |  _ d |  _ d |  _ n
 |  j ƒ  d  S(	   Nt   completionsi   s   def s   class t    i   t    i    (   t   __dict__t   updatet   namet   filenamet   source_codet   is_python_liket   in_comment_or_stringt   sys_patht   positiont   _get_docstringt	   docstringt
   startswitht   indext   linest   columnt   line_numt   linet   objt   full_objt	   _get_info(
   t   selfR   R   R   R   R   R   R   t   kwargst   base(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   __init__#   s6    															c         C   s«  |  j  |  j  j ƒ  |  _ t |  j ƒ |  _ |  j d |  _ t |  j d ƒ |  _ |  j  j ƒ  |  j d } t |  j	 ƒ } t t
 | j d ƒ ƒ ƒ d k rgt j |  j |  j ƒ } | rß |  j j | d ƒ rß | d |  _ n	 d  |  _ |  j |  _ |  j r[|  j  j ƒ  |  j d } | |  j } t j |  j | ƒ } | r[|  j | j ƒ  |  _ q[n  d  |  _ n  d } | j | ƒ } xˆ | D]€ \ } }	 | t |	 ƒ 7} | |  j k rƒ|	 t |	 ƒ | |  j  |  _ |	 |  _ | t j j k röt j j } n  | |  _ PqƒqƒW|  j d k r§|  j t j k r§|  j r§t j |  j |  j ƒ }
 |
 r§|
 d |  _ |  j j |  j ƒ t |  j ƒ |  _ |  j t |  j ƒ |  j |  _ q§n  d  S(   Niÿÿÿÿi   s   a bi    t   infot
   definition(   R#   R$   (   R   R   t
   splitlinesR   t   lenR   R   R   t   find_lexer_for_filenameR   t   listt
   get_tokenst   ret   findallt   id_regext   endswithR   t   NoneR   t   matcht   groupt   contextR   t   Literalt   StringR   t   NameR   t   func_call_regexR   (   R   t	   full_linet   lexert   tokenst   restR/   t   post   line_tokensR1   t   tokent	   func_call(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyR   K   sJ    !				!	%c         C   sÌ   |  j  } x< | rG |  j | | d !d k r: | d 7} Pn  | d 8} q W|  j  } xK | t |  j ƒ k  rž |  j | d | !d k r‘ | d 8} Pn  | d 7} qT W| rÈ | t |  j ƒ k  rÈ |  j | | !Sd S(   s'   Find the docstring we are currently in.i   s   """s   '''i   R
   (   s   """s   '''(   s   """s   '''(   R   R   R&   (   R   t   leftt   right(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyR   €   s    		
	
c         C   s3   y |  j  ƒ  | j  ƒ  k SWn t k
 r. t SXd  S(   N(   t	   serializet	   Exceptiont   False(   R   t   other(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   __eq__’   s    c         C   s   t  |  | ƒ S(   s   Allow dictionary-like access.(   t   getattr(   R   t   item(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   __getitem__˜   s    c         C   ss   i  } xL |  j  j ƒ  D]; \ } } y t j | ƒ | | | <Wq t k
 rP q Xq W|  j | d <|  j | d <| S(   NR,   R5   (   R   t   itemst   picklet   dumpsRA   R,   R5   (   R   t   statet   keyt   value(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyR@   œ   s    N(   t   __name__t
   __module__R*   t   compilet   UNICODER,   R5   R.   RB   R"   R   R   RD   RG   R@   (    (    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyR      s   	&	5			c         C   so   |  p	 d }  t  j j |  ƒ \ } } | t k rC t t | ƒ } n( y t |  ƒ } Wn t k
 rj t ƒ  SX| S(   s+   Get a Pygments Lexer given a filename.
    R
   (   t   ost   patht   splitextR   R   R   RA   R   (   R   t   roott   extR7   (    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyR'   ©   s    c         C   sP  t  |  d ƒ s g  Sd |  j k rI y |  j d d d j SWqI qI Xn  g  } xú |  j j ƒ  D]é } xà | D]Ø } y» t | d t ƒ rŸ | j | d j ƒ n | d } d | d k sÉ d | d k r,t j d d | d ƒ } t j d d | ƒ } d	 | k r| j | j d	 ƒ ƒ q,| j	 | ƒ n  Wql t
 k
 rCql ql Xql Wq_ W| S(
   s(   Get the keywords for a given lexer.
    R8   t   keywordsi    s   )\bs   )(\s+)s   \\.R
   s   [^0-9a-zA-Z|]+t   |(   t   hasattrR8   R   t   valuest
   isinstancet   extendR*   t   subt   splitt   appendRA   (   R7   RW   t   valst   valt   ini_val(    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   get_keywords¸   s.    
 c         C   s  |  d k r$ | d k s6 | d k s6 |  rK | rK | rK d } t | ƒ ‚ n  |  r£ | d k r£ | d k r£ t j j |  ƒ d } t |  ƒ  } | j ƒ  } Wd QXn  | d k rÁ t j d ƒ } n- | d k rß t j d ƒ } n t j d ƒ } t	 t
 | j d | ƒ j ƒ  ƒ ƒ } | S(   sÑ   
    Extract all words from a source code file to be used in code completion.

    Extract the list of words that contains the file in the editor,
    to carry out the inline completion similar to VSCode.
    s5   Must provide `file_path` or `content` and `extension`i   Ns   .csss   ([^a-zA-Z-])s   .Rs   .cs   .mds   .cpps   .javas   .pys   ([^a-zA-Z_])s   ([^a-zA-Z])R	   (   s   .css(   s   .Rs   .cs   .mds   .cpps   .javas   .py(   R.   RA   RR   RS   RT   t   opent   readR*   RP   t   sortedt   setR]   R^   (   t	   file_patht   contentt	   extensiont	   error_msgt   infilet   regexR   (    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt	   get_wordsÕ   s    $$c         C   sØ   t  j |  ƒ } y9 t  j |  ƒ } t  j | ƒ d } t j | | g ƒ Wn t k
 r\ d SX| g } x\ | j t  j | ƒ ƒ y- t  j | ƒ } t j d | t j	 g ƒ Wqi t k
 rÀ Pqi Xqi Wd j
 t | ƒ ƒ S(   s™   
    Given a file path, determine the full module path.

    e.g. '/usr/lib/python2.7/dist-packages/numpy/core/__init__.pyc' yields
    'numpy.core'
    i    NR"   t   .(   t   ospt   dirnamet   basenameRT   t   impt   find_modulet   ImportErrorR_   RR   t   sept   joint   reversed(   RS   Rq   t   modRH   (    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   get_parent_untilð   s     		c           C   s%   t  d d d d d d d d d d ƒ S(   s&   Default response when asking for info.R   R
   t   argspect   noteR   t   calltip(   t   dict(    (    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   default_info_response
  s    (   t   __doc__Rs   RR   RI   t   os.pathRS   Rp   R*   t   spyder.utils.miscR    t   spyder.utils.syntaxhighlightersR   t   pygments.lexerR   t   pygments.lexersR   R   R   t   pygments.tokenR   t   objectR   R'   Rc   R.   Rn   Rz   R   (    (    (    s?   lib/python2.7/site-packages/spyder/utils/introspection/utils.pyt   <module>	   s    Œ		