ó
‹²,]c           @@  s¢   d  Z  d d l m 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 d d l m Z d d	 l m Z d
 e f d „  ƒ  YZ d S(   sT   
Widget that handles communications between the IPython Console and
the Help plugin
i    (   t   absolute_importN(   t   ANSI_OR_SPECIAL_PATTERN(   t   RichJupyterWidget(   t
   QEventLoop(   t   getargspecfromtextt   getsignaturefromtext(   t   _(   t   PY3t
   HelpWidgetc           B@  sG   e  Z d  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z	 RS(   s‡   
    Widget with the necessary attributes and methods to handle communications
    between the IPython Console and the Help plugin
    c         C@  s   t  j d d | ƒ S(   sŠ   
        Replace invalid variable chars in a string by underscores

        Taken from https://stackoverflow.com/a/3305731/438386
        s
   \W|^(?=\d)R   (   t   ret   sub(   t   selft   var(    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt   clean_invalid_var_chars    s    c         C@  sè   | j  d i  ƒ } | j  d d ƒ } | rà t j d | ƒ } |  j |  j _ |  j j ƒ  } | d  j d ƒ d } | j d ƒ d } y  |  j | ƒ j d ƒ d } Wn n Xt	 | ƒ } | rÍ | | } n t
 | | ƒ } | Sd Sd S(	   s(   Get signature from inspect reply contentt   datas
   text/plaint    iÿÿÿÿt   (t   .R   N(   t   getR   R
   t   _prompt_post   _controlt   current_prompt_post   get_current_line_to_cursort   splitR   R   R   (   R   t   contentR   t   textt   linet   namet   argspect	   signature(    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt   get_signature(   s$     c         C@  sj   |  j  r d St ƒ  } |  j j | j ƒ |  j d | | f ƒ | j ƒ  |  j j | j ƒ d } |  j	 S(   s    Return True if object is definedNs6   get_ipython().kernel.is_defined('%s', force_import=%s)(
   t   _readingR   t   sig_got_replyt   connectt   quitt   silent_exec_methodt   exec_t
   disconnectt   Nonet   _kernel_reply(   R   t   objtxtt   force_importt	   wait_loop(    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt
   is_definedC   s    		
c         C@  sd   |  j  r d St ƒ  } |  j j | j ƒ |  j d | ƒ | j ƒ  |  j j | j ƒ d } |  j	 S(   s#   Get object documentation dictionaryNs"   get_ipython().kernel.get_doc('%s')(
   R   R   R    R!   R"   R#   R$   R%   R&   R'   (   R   R(   R*   (    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt   get_docT   s    		
c         C@  sd   |  j  r d St ƒ  } |  j j | j ƒ |  j d | ƒ | j ƒ  |  j j | j ƒ d } |  j	 S(   s   Get object sourceNs%   get_ipython().kernel.get_source('%s')(
   R   R   R    R!   R"   R#   R$   R%   R&   R'   (   R   R(   R*   (    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt
   get_sourcec   s    		
c         C@  sÈ   |  j  ƒ  } |  j j d ƒ } | rÄ | j | d d k rÄ | j | j ƒ  k rÄ | d } | j d ƒ d k rÄ | j d t ƒ rÄ |  j | ƒ } | rÁ |  j j	 t
 d ƒ | d	 t d
 d ƒqÁ qÄ n  d S(   s†   
        Reimplement call tips to only show signatures, using the same
        style from our Editor and External Console too
        t   call_tipt   parent_headert   msg_idR   t   statust   okt   foundt	   ArgumentsR   t   colors   #2D62FFN(   t   _get_cursort   _request_infoR   t   idt   post   positiont   FalseR   R   t   show_calltipR   t   True(   R   t   rept   cursort   infoR   R   (    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt   _handle_inspect_replys   s    
'(
   t   __name__t
   __module__t   __doc__R   R   R;   R+   R,   R-   RA   (    (    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyR      s   				(   RD   t
   __future__R    R	   t   qtconsole.ansi_code_processorR   t   qtconsole.rich_jupyter_widgetR   t   qtpy.QtCoreR   t   spyder_kernels.utils.dochelpersR   R   t   spyder.config.baseR   t   spyder.py3compatR   R   (    (    (    sA   lib/python2.7/site-packages/spyder/widgets/ipythonconsole/help.pyt   <module>
   s   