ó
‹²,]c           @  s}  d  d l  m Z d  d l m 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 d  d l m Z m Z m Z m Z d  d l m Z d  d	 l m Z d  d
 l m Z d d d g Z e d ƒ Z e d k Z d Z d Z e j d e d ƒ d e ƒd Z e j d e d ƒ d e ƒd e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d e" f d „  ƒ  YZ# d S(   iÿÿÿÿ(   t   print_function(   t   OrderedDictN(   t   QObjectt   QTimert   Signal(   t   QApplication(   t   dependencies(   t   _t   DEBUGt   debug_printt   get_conf_path(   t
   sourcecode(   t   PluginClient(   t   CodeInfot   ropet   jedit   fallbacks   introspection.logi   g      Ð?s   >=0.9.4s3   Editor's code completion, go-to-definition and helpt   required_versions   >=0.9.0t   PluginManagerc           B  sS   e  Z e e ƒ Z d  „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   c         C  s  t  t |  ƒ j ƒ  t ƒ  } x t D]… } y t | | ƒ } | j ƒ  Wn4 t k
 r| } t d | ƒ t t	 | ƒ ƒ q# n Xt d | ƒ | | | <| j
 j |  j ƒ q# W| |  _ t ƒ  |  _ g  |  _ t ƒ  |  _ d  |  _ d  |  _ d  |  _ d  |  _ t |  _ d  S(   Ns   Introspection Plugin Failed: %ss   Introspection Plugin Loaded: %s(   t   superR   t   __init__R   t   PLUGINSR   t   runt	   ExceptionR	   t   strt   receivedt   connectt   handle_responset   pluginsR   t   timert   desiredt   dictt   idst   Nonet   infot   requestt   pendingt   pending_requestt   Falset   waiting(   t   selft
   executableR   t   namet   plugint   e(    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR   /   s,    	
						c   	      C  s6  |  j  r> | j ƒ  |  j j ƒ  k r0 | |  _ n
 t d ƒ d St d | j ƒ d } | |  _ | j } | j d k r¦ d |  j k r¦ | j	 j
 ƒ  j d ƒ r¦ d } n  | j ƒ  sà t j | j ƒ sà | j ƒ  ré | j d	 k ré d } n  |  j j ƒ  } | r|  j | g } | g |  _ n~ | j d
 k r<| j j ƒ  sK| j d	 k rft |  j j ƒ  ƒ |  _ n5 t |  j j ƒ  ƒ d  } t |  j j ƒ  ƒ d  |  _ t j ƒ  |  _ t |  _  d | j } | j ƒ  } t ƒ  |  _ x0 | D]( } | j | | ƒ } | j |  j | <qßW|  j j ƒ  |  j j t d |  j  ƒ d S(   s)   Handle an incoming request from the user.s   skipping duplicate requestNs
   %s requestt
   completionR   s   import s   from R   R"   t
   definitioniÿÿÿÿs   get_%siè  (   s   import s   from (!   R'   t	   serializeR"   R%   R	   R*   R!   t   editorR   t   linet   lstript
   startswitht   is_python_likeR   t
   is_keywordt   objt   in_comment_or_stringt   valuesR   t	   is_pythont   listt   keyst   timet   _start_timet   TrueR   R    R#   R   t   stopt
   singleShott   LEAD_TIME_SECt   _handle_timeout(	   R(   R"   R   R0   R   t   methodt   valueR+   t
   request_id(    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   send_requestH   sF    	
					c         C  s+   x$ |  j  j ƒ  D] } | j d ƒ q Wd  S(   Nt   validate(   R   R8   R#   (   R(   R+   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRG   t   s    c         C  s™   |  j  j | d d  ƒ } | s# d  S| j d d  ƒ rJ t d | d ƒ d  S| |  j d k sg |  j rŒ | j d d  ƒ r• |  j | ƒ q• n	 | |  _ d  S(   NRE   t   errors   Response error:i    t   result(   R    t   getR!   R	   R   R'   t	   _finalizeR$   (   R(   t   responseR*   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR   x   s    c         C  sA   x: |  j  j ƒ  D]) \ } } | j ƒ  t d j | ƒ ƒ q Wd  S(   Ns   Introspection Plugin Closed: {}(   R   t   itemst   closeR	   t   format(   R(   R*   R+   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRN   …   s    
c         C  s¸   t  |  _ d  |  _ |  j r‰ t j ƒ  |  j } t d |  j j | d t	 | d ƒ d  | f ƒ |  j | d <d  |  _ |  j
 j | ƒ n  |  j r´ |  j } d  |  _ |  j | ƒ n  d  S(   Ns-   %s request from %s finished: "%s" in %.1f secR*   RI   id   R"   (   R&   R'   R!   R$   R"   R<   R=   R	   R*   R   t   sig_introspection_completet   emitR%   RF   (   R(   RL   t   deltaR"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRK   Š   s    							c         C  s3   t  |  _ |  j r% |  j |  j ƒ n
 t d ƒ d  S(   Ns   No valid responses acquired(   R&   R'   R$   RK   R	   (   R(   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRB   š   s    		(   t   __name__t
   __module__R   t   objectRP   R   RF   RG   R   RN   RK   RB   (    (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR   +   s   		,				t   IntrospectionManagerc           B  sÑ   e  Z e e e e e e ƒ Z e e e e ƒ Z d g  d  „ Z	 d „  Z
 d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z e d „ Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c         C  s‰   t  t |  ƒ j ƒ  d  |  _ d  |  _ t j |  _ | |  _	 |  j	 rW |  j j
 | ƒ n  | |  _ t | ƒ |  _ |  j j j |  j ƒ d  S(   N(   R   RV   R   R!   t   editor_widgetR$   t   syst   patht   sys_patht
   extra_patht   extendR)   R   t   plugin_managerRP   R   t   introspection_complete(   R(   R)   R[   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR   §   s    					c         C  s   | |  _  |  j ƒ  d  S(   N(   R)   t   _restart_plugin(   R(   R)   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   change_executable´   s    	c         C  s<   | |  j  k r8 | |  _  t j |  _ |  j j | ƒ n  d S(   s&   Change extra_path and update sys_path.N(   R[   RX   RY   RZ   R\   (   R(   R[   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   change_extra_path¸   s    	c         C  s9   |  j  j ƒ  t |  j ƒ |  _  |  j  j j |  j ƒ d  S(   N(   R]   RN   R   R)   RP   R   R^   (   R(   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR_   ¿   s    c         C  s   | |  _  d  S(   N(   RW   (   R(   RW   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   set_editor_widgetÅ   s    c         K  sž   |  j  j ƒ  } |  j  j ƒ  } | j ƒ  } | d  k rH | j d ƒ } n  | | d <| | d <|  j  | d <|  j | d <t | | j ƒ  | | j	 | j
 | |  S(   Nt   cursorR0   t   finfoRW   RZ   (   RW   t   get_current_editort   get_current_finfoR7   R!   t   get_positionRZ   R   t   get_source_codet   filenameR4   (   R(   R*   t   positiont   kwargsR0   Rd   R7   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   _get_code_infoÈ   s    

c         C  s)   |  j  d d | ƒ} |  j j | ƒ d S(   s   Get code completiont   completionst	   automaticN(   Rl   R]   RF   (   R(   Rn   R"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   get_completionsÚ   s    c         C  s&   |  j  d | ƒ } |  j j | ƒ d S(   s   Go to definitionR.   N(   Rl   R]   RF   (   R(   Rj   R"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   go_to_definitionß   s    c         C  s,   |  j  d | d | ƒ} |  j j | ƒ d S(   s:   Show signature calltip and/or docstring in the Help pluginR"   t   autoN(   Rl   R]   RF   (   R(   Rj   Rq   R"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   show_object_infoä   s    c         C  s   |  j  j ƒ  d S(   s   Validate the pluginsN(   R]   RG   (   R(   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRG   í   s    c         C  s<   |  j  r8 |  j  j ƒ  } t | d ƒ r8 | j r8 t Sn  d S(   s$   Check if the main app is starting upt   is_starting_upN(   RW   t   windowt   hasattrRs   R>   (   R(   Rt   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   is_editor_readyñ   s    	c         C  s¬   | j  d d ƒ } | d k r" d S| d } |  j | d d ƒ } | r¨ | j | j k r¨ t |  d | j ƒ } y | | | | ƒ Wq¨ t k
 r¤ } t | ƒ q¨ Xn  d S(   sr   
        Handle an introspection response completion.

        Route the response to the correct handler.
        RI   NR"   R*   s   _handle_%s_result(   RJ   R!   Rl   Ri   t   getattrR*   R   R	   (   R(   RL   RI   R"   t   currentt   funcR,   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR^   ø   s    
c         C  s¹  | j  | j  k r d S| j } | j } | j d k rF d } d } n  | j | ƒ sY d S| j rt | j ƒ t | j ƒ k rg  | D]* \ } } | j | j ƒ r‡ | | f ^ q‡ } | r| j j d ƒ }	 |	 t | j ƒ t | j ƒ }
 | j j |
 ƒ | j } | } qn  d | k r6| j	 d ƒ d } n  g  | D]% \ } } | j	 d ƒ d | f ^ q=} g  | D]' \ } } | j | ƒ ro| | f ^ qo} | j j
 | | | j ƒ d S(   s¬   
        Handle a `completions` result.

        Only handle the response if we are on the same line of text and
        on the same `obj` as the original request.
        Nt    Rc   t   .iÿÿÿÿ(   t   line_numR6   R!   R3   t   full_objt   lenR0   Rg   t   set_cursor_positiont   splitt   show_completion_listRn   (   R(   t	   comp_listR"   t	   prev_infot   completion_textt	   prev_textt   ct   tt   new_listt   post   new_pos(    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   _handle_completions_result  s2    			'$ 	2!c         C  s}   | j  | j  k r d S| d rI | j j d | d d t d | j ƒn  |  j j | d | d | d | d	 | j ƒ d S(
   sÁ   
        Handle an `info` result, triggering a calltip and/or docstring.

        Only handle the response if we are on the same line of text as
        when the request was initiated.
        Nt   calltipt	   Argumentst	   signaturet   at_positionR*   t   argspect   notet	   docstring(   R|   R0   t   show_calltipR>   Rj   t   sig_send_to_helpRQ   Rq   (   R(   t   respR"   Rƒ   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   _handle_info_result2  s    
c         C  s&   | \ } } |  j  j | | d ƒ d S(   s   Handle a `definition` resultRz   N(   t   sig_edit_gotoRQ   (   R(   R•   R"   Rƒ   t   fnamet   lineno(    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   _handle_definition_resultG  s    i`ê  c         C  sW   |  j  rS y3 |  j  j ƒ  j ƒ  } | j | | ƒ t j ƒ  WqS t k
 rO qS Xn  d S(   sS   
        Post a message to the main window status bar with a timeout in ms
        N(   RW   Rt   t	   statusBart   showMessageR   t   processEventst   AttributeError(   R(   t   messaget   timeoutt	   statusbar(    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   _post_messageL  s    	N(   RS   RT   R   R   t   boolR”   t   intR—   R!   R   R`   Ra   R_   Rb   Rl   Ro   Rp   R>   Rr   RG   Rv   R^   R‹   R–   Rš   R¢   (    (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRV   ¢   s$   											'		t   IntrospectionPluginc           B  s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C  s   d S(   s   Initialize the pluginN(    (   R(   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   load_plugin[  s    c         C  s   d S(   s   Get a list of completionsN(    (   R(   R"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRo   _  s    c         C  s   d S(   sX  
        Find the calltip and docs

        Returns a dict like the following:
           {'note': 'Function of numpy.core.numeric...',
            'argspec': "(shape, dtype=None, order='C')'
            'docstring': 'Return an array of given...'
            'name': 'ones',
            'calltip': 'ones(shape, dtype=None, order='C')'}
        N(    (   R(   R"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   get_infoc  s    c         C  s   d S(   s4   Get a (filename, line_num) location for a definitionN(    (   R(   R"   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   get_definitionp  s    c         C  s   d S(   s   Validate the pluginN(    (   R(   (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyRG   t  s    (   RS   RT   R¦   Ro   R§   R¨   RG   (    (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyR¥   Y  s
   				($   t
   __future__R    t   collectionsR   R<   RX   t   qtpy.QtCoreR   R   R   t   qtpy.QtWidgetsR   t   spyderR   t   spyder.config.baseR   R   R	   R
   t   spyder.utilsR   t(   spyder.utils.introspection.plugin_clientR   t    spyder.utils.introspection.utilsR   R   t   LOG_FILENAMEt   DEBUG_EDITORRA   t   ROPE_REQVERt   addt   JEDI_REQVERR   RV   RU   R¥   (    (    (    sA   lib/python2.7/site-packages/spyder/utils/introspection/manager.pyt   <module>   s2   "		w·