
c?[c           @  s  d  Z  d d l m Z d d l Z d d l Z d d l m Z d d l m 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 y d d l m Z Wn! e k
 r d d l m Z n Xd 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 m Z m Z m  Z  m! Z! 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 l, m- Z- d d l. m/ Z/ m0 Z0 d d l1 m2 Z2 d d l3 m4 Z4 m5 Z5 d d l6 m7 Z7 m8 Z8 m9 Z9 m: Z: d d l; m< Z< d d l= m> Z> m? Z? m@ Z@ d d lA mB ZB d d lC mD ZD d d lE mF ZF d d lG mH ZH d d lI mJ ZJ d d lK mL ZL d d lM mN ZN d d lO mP ZP d d  lQ mR ZR d d! lS mT ZT d d" lU mV ZV d d d#  ZX d$   ZY d% e/ f d&     YZZ d' e' f d(     YZ[ d S()   sD   IPython terminal interface using prompt_toolkit in place of readlinei(   t   print_functionN(   t   getpass(   t   BytesIO(   t   warn(   t   Empty(   t   ZMQError(   t   page(   t   cast_unicode_py2t   input(   t   NamedFileInTemporaryDirectory(	   t   Boolt   Integert   Floatt   Unicodet   Listt   Dictt   Enumt   Instancet   Any(   t   SingletonConfigurablei   (   t   ZMQCompleter(   t   ZMQHistoryManager(   t   __version__(   t	   Completert
   Completion(   t   Document(   t   DEFAULT_BUFFERt   EditingMode(   t   HasFocust   HasSelectiont   ViInsertModet   EmacsInsertMode(   t   InMemoryHistory(   t   create_prompt_applicationt   create_eventloopt   create_output(   t   CommandLineInterface(   t   KeyBindingManager(   t	   InputMode(   t   ViStateFilter(   t   Keys(   t   PygmentsLexer(   t   PygmentsStyle(   t   get_style_by_name(   t   get_lexer_by_name(   t   ClassNotFound(   t   Tokenc         C  s   i t  d 6t d 6t  d 6t d 6} d } x | | j   k r y) t |  d  j   } | se | } n  Wq+ t k
 r | r | } q q+ t k
 r | | j   k r | } t   q   q+ Xq+ W| | S(   s  Asks a question and returns a boolean (y/n) answer.

    If default is given (one of 'y','n'), it is used if the user input is
    empty. If interrupt is given (one of 'y','n'), it is used if the user
    presses Ctrl-C. Otherwise the question is repeated until an answer is
    given.

    An EOF is treated as the default answer.  If there is no default, an
    exception is raised to prevent infinite loops.

    Valid answers are: y/yes/n/no (match is not case sensitive).t   yt   nt   yest   not    N(	   t   Truet   Falset   Nonet   keysR   t   lowert   KeyboardInterruptt   EOFErrort   print(   t   promptt   defaultt	   interruptt   answerst   ans(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt
   ask_yes_no3   s     "
c         C  s   |  j    }  |  d k r, d d l m } | S|  d k rL d d l m } | Sy t |   j SWn0 t k
 r t d |   d d l m	 } | SXd  S(   Nt   ipython2i(   t   IPythonLexert   ipython3(   t   IPython3Lexers7   No lexer found for language %r. Treating as plain text.(   t	   TextLexer(
   R8   t   IPython.lib.lexersRC   RE   R,   t	   __class__R-   R   t   pygments.lexers.specialRF   (   t   nameRC   RE   RF   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   get_pygments_lexerS   s    t   JupyterPTCompleterc           B  s    e  Z d  Z d   Z d   Z RS(   s7   Adaptor to provide kernel completions to prompt_toolkitc         C  s   | |  _  d  S(   N(   t   jup_completer(   t   selfRM   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   __init__f   s    c         c  so   | j  j   s d  S|  j j d | j d | j  } | d | j } x# | d D] } t | d | VqP Wd  S(   Nt   codet
   cursor_post   cursor_startt   matchest   start_position(   t   current_linet   stripRM   t   complete_requestt   textt   cursor_positionR   (   RN   t   documentt   complete_eventt   contentt	   start_post   m(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   get_completionsi   s    	(   t   __name__t
   __module__t   __doc__RO   R_   (    (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRL   d   s   	t   ZMQTerminalInteractiveShellc        	   B  s}  e  Z e Z dJ Z e Z e d   Z e Z	 dJ Z
 e Z e d d e d d Z e d  d e d d Z e d e d d  Z e e d e d d Z e d d e d d	 Z e d
 d e d d Z e d d e d d Z e dK d d e d e d d Z e d e d d  Z e d e d d  Z e d e d d  Z e d d d d g d e d d  Z e e d e d d Z  e d d e d d Z! e e d e d d Z" e# d  d e Z$ e# d! d e Z% d"   Z& e   Z' d#   Z( e e d d$ j) d e  Z* d%   Z+ d&   Z, d'   Z- d(   Z. d)   Z/ d*   Z0 d+   Z1 i  Z2 d,   Z3 d-   Z4 d.   Z5 d/   Z6 d0   Z7 d1   Z8 d2   Z9 dJ Z: d3   Z; dJ d4  Z< d5   Z= e d6  Z> dJ d7  Z? dJ d8  Z@ e e d e d d9 ZA e d: d e d d; ZB d<   ZC d=   ZD d  d>  ZE i d? d 6d@ d 6dA d 6ZF dB   ZG dC   ZH dD   ZI dE   ZJ dF   ZK dG   ZL dH dI  ZM RS(L   t    t   emacst   configt   helps5   Shortcut style to use at the prompt. 'vi' or 'emacs'.s;   The name of a Pygments style to use for syntax highlightings0   Override highlighting format for specific tokenss   Use 24bit colors instead of 256 colors in prompt highlighting. If your terminal supports true color, the following command should print 'TRUECOLOR' in orange: printf "\x1b[38;2;255;100;0mTRUECOLOR\x1b[0m\n"i  s*   How many history items to load into memorys*   Jupyter console {version}

{kernel_banner}sh   Text to display before the first prompt. Will be formatted with variables {version} and {kernel_banner}.i<   s5  Timeout for giving up on a kernel (in seconds).

        On first connect and restart, the console tests whether the
        kernel is running and responsive by sending kernel_info_requests.
        This sets the timeout in seconds for how long the kernel can take
        before being presumed dead.
        t   PILt   streamt   tempfilet   callablet
   allow_nones2  
        Handler for image type output.  This is useful, for example,
        when connecting to the kernel in which pylab inline backend is
        activated.  There are four handlers defined.  'PIL': Use
        Python Imaging Library to popup image; 'stream': Use an
        external program to show the image.  Image will be fed into
        the STDIN of the program.  You will need to configure
        `stream_image_handler`; 'tempfile': Use an external program to
        show the image.  Image will be saved in a temporally file and
        the program is called with the temporally file.  You will need
        to configure `tempfile_image_handler`; 'callable': You can set
        any Python callable which is called with the image data.  You
        will need to configure `callable_image_handler`.
        s6  
        Command to invoke an image viewer program when you are using
        'stream' image handler.  This option is a list of string where
        the first element is the command itself and reminders are the
        options for the command.  Raw image data is given as STDIN to
        the program.
        s  
        Command to invoke an image viewer program when you are using
        'tempfile' image handler.  This option is a list of string
        where the first element is the command itself and reminders
        are the options for the command.  You can use {file} and
        {format} in the string to represent the location of the
        generated image file and image format.
        s  
        Callable object called via 'callable' image handler with one
        argument, `data`, which is `msg["content"]["data"]` where
        `msg` is the message from iopub channel.  For exmaple, you can
        find base64 encoded PNG data as `data['image/png']`. If your function
        can't handle the data supplied, it should return `False` to indicate
        this.
        t   default_values	   image/pngs
   image/jpegs   image/svg+xmlst   
        Preferred object representation MIME type in order.  First
        matched MIME type will be used.
        s   Whether to use the kernel's is_complete message
        handling. If False, then the frontend will use its
        own is_complete handler.
        i   s%  Timeout (in seconds) for giving up on a kernel's is_complete
        response.

        If the kernel does not respond at any point within this time,
        the kernel will no longer be asked if code is complete, and the
        console will default to the built-in is_complete test.
        s   Set to display confirmation dialog on exit.
        You can always use 'exit' or 'quit', to force a
        direct exit without any confirmation.
        s   jupyter_client.KernelManagers   jupyter_client.KernelClientc         C  s   | j  j  |  _ d  S(   N(   t   sessiont
   session_id(   RN   RJ   t   oldt   new(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   _client_changed   s    c         C  s   d j  d t  S(   Ns   Jupyter Console {version}
t   version(   t   formatR   (   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   _banner1_default   s    s4   Use simple fallback prompt. Features may be limited.c         K  sj   t  t |   j |   |  g |  _ |  j   |  j   |  j   |  j   |  j   t	 |  _
 d |  _ d  S(   Ni   (   t   superRc   RO   t   configurablest   init_historyt   init_completert   init_iot   init_kernel_infot   init_prompt_toolkit_cliR4   t   keep_runningt   execution_count(   RN   t   kwargs(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRO     s    




	c         C  s"   t  |  |  j d |  j |  _ d S(   sN  Initialize the completion machinery.

        This creates completion machinery that can be used by client code,
        either interactively in-process (typically triggered by the readline
        library), programmatically (such as in test suites) or out-of-process
        (typically over the network by remote frontends).
        Rf   N(   R   t   clientRf   R   (   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRy     s    c         C  s,   t  d |  j  |  _ |  j j |  j  d S(   s   Sets up the command history. R   N(   R   R   t   history_managerRw   t   append(   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRx     s    c         C  s1   t  j d f t  j t |  j  f t  j d f g S(   Ns   In [s   ]: (   R.   t   Promptt	   PromptNumt   strR~   (   RN   t   cli(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   get_prompt_tokens$  s    c         C  s   t  j d | d d f g S(   NR3   i   s   : (   R.   R   (   RN   R   t   width(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   get_continuation_tokens+  s    c         C  s1   t  j d f t  j t |  j  f t  j d f g S(   Ns   Out[s   ]: (   R.   t	   OutPromptt   OutPromptNumR   R~   (   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   get_out_prompt_tokens0  s    c         C  s   |  j  j |  j    d  S(   N(   t   pt_clit   print_tokensR   (   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   print_out_prompt7  s    c         C  s   |  j  } t j   } |  j j j   |  j j   } x t r y |  j j d d  } Wn6 t k
 r t j   | | k r t	 d   q q7 X| d j
 d  | k r7 | d |  _ d Sq7 Wd S(   s4   Wait for a kernel to be ready, and store kernel infot   timeouti   s,   Kernel didn't respond to kernel_info_requestt   parent_headert   msg_idR\   N(   t   kernel_timeoutt   timeR   t
   hb_channelt   unpauset   kernel_infoR4   t   get_shell_msgR   t   RuntimeErrort   get(   RN   R   t   ticR   t   reply(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR{   ;  s    		c         C  s2   t  |  j j d t d |  j j d d    d  S(   NRs   t   kernel_bannert   bannerRd   (   R;   R   Rt   R   R   R   (   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   show_bannerL  s    c           s    j  s d t j k rF   f d   } |   _   f d     _ d  St j   } t   t   B} | j	 j
 t j d t t  t   @| @  f d    } | j	 j
 t j d t t  d    } | j	 j
 t j d t t  d    } t   } d } x`   j j   j d	 t D]C \ } } } t | j    } | r| | k r| j |  qqWi d
 t j 6d t j 6d t j 6d t j 6}   j rt    j  }	 n^ t  d  }	 | j! i d t j" 6d t j# 6d t j$ 6d t j% j& 6d t j% j' 6d t j% j( 6 | j!   j)  t* j+ d |	 d |  }
 t, t-   j. j/    }   j0 j1 d i   } | j1 d | j1 d d   } t2 d t d | d t3 t4 |   d   j5 d   j6 d | j	 d  | d! t7   j8  d" t d# |
  
} t9     _: t; | d$   j: d% t< d&   j=    _> d  S('   Nt   JUPYTER_CONSOLE_TESTc             s   t  t d   j   S(   Ns	   In [%d]: (   R   R   R~   (    (   RN   (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR<   T  s    c             s   t  d   j d d S(   Ns	   Out[%d]: t   endRd   (   R;   R~   (    (   RN   (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   <lambda>X  s    t   filterc           s   |  j  } | j } | j p4 | j | j | j   k sE | j   d  S  j     j | j	  \ } } | r | j
 j r | j
 j |  j |  n | j d |  d  S(   Ns   
(   t   current_bufferRZ   t   on_last_linet   cursor_position_rowt
   line_countt   empty_line_count_at_the_endt   newlinet   handle_iopubt   check_completeRX   t   accept_actiont   is_returnablet   validate_and_handleR   t   insert_text(   t   eventt   bt   dt   moret   indent(   RN   (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   _^  s    		

c         S  s   |  j  j   d  S(   N(   R   t   reset(   R   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR   v  s    c         S  s
   t   d  S(   N(   R:   (   R   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR   z  s    u    t   include_latests   #009900s   #00ff00 bolds   #ff2200s   #ff0000 boldR=   s   #007700t	   noinherits   #BB6622s   #2080D0s   bold #2080D0t   pygments_style_clst
   style_dictt   language_infot   pygments_lexerRJ   RX   t	   multilinet   editing_modet   lexerR   R   t   key_bindings_registryt   historyt	   completert   enable_history_searcht   stylet	   eventloopt   outputt
   true_color(?   t   simple_promptt   ost   environt   prompt_for_codeR   R%   t
   for_promptR   R   t   registryt   add_bindingR(   t   ControlJR   R   R   t   ControlCt   ControlBackslashR    R   t   get_tailt   history_load_lengthR4   R   t   rstripR   R.   R   R   R   R   t   highlighting_styleR+   t   updatet   Numbert   Operatort   Stringt   Namet   Functiont   Classt	   Namespacet   highlighting_style_overridesR*   t   from_defaultst   getattrR   R   t   upperR   R   R!   R)   RK   R   R   RL   R   R"   t
   _eventloopR$   R#   R   R   (   RN   R<   t	   kbmanagert   insert_modeR   R   t	   last_cellt   cellt   style_overridest	   style_clsR   R   t   langinfoR   t   app(    (   RN   s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR|   P  sj    	***	


		


							c         C  s%   |  j  j d |  j d t  } | j S(   Nt   pre_runt   reset_current_buffer(   R   t   runt
   pre_promptR4   RX   (   RN   RZ   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR     s    	c         C  s3   t  j d d h k r d  Sd d  l } | j   d  S(   Nt   win32R   i(   t   syst   platformt   coloramat   init(   RN   R   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRz     s    c         C  s   |  j  rS |  j j |  } y |  j | d |  j SWq t k
 rO t d f SXn< | j   } t |  r | d d k } | d f St d f Sd  S(   NR   Rd   i(	   t   use_kernel_is_completeR   t   is_completet   handle_is_complete_replyt   kernel_is_complete_timeoutt   SyntaxErrorR5   t
   splitlinest   len(   RN   RP   R   t   linesR   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR     s    	
c         C  s   t  |  _ d  S(   N(   R5   R}   (   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   ask_exit  s    c           si    j  re t  j        f d   } t  j d  rR  j j j |  n |   d   _  n  d  S(   Nc             s   t      j j j _ d  S(   N(   R   R   t   applicationt   bufferRZ   (    (   t   sRN   (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   set_doc  s    t   pre_run_callables(   t
   next_inputR   t   hasattrR   R  R   R6   (   RN   R   (    (   R   RN   s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR     s    	c         C  s   x |  j  r t d d d y |  j   } Wn: t k
 rh |  j sX t d d d  r |  j   q q X| r |  j | d t q q Wd  S(   Ns   
R   Rd   s#   Do you really want to exit ([y]/n)?R/   R0   t   store_history(	   R}   R;   R   R:   t   confirm_exitRA   R   t   run_cellR4   (   RN   t   display_bannerRP   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   interact  s    
c         C  s   |  j  |  _ x7 t rF y |  j   PWq t k
 rB t d  q Xq W|  j r` |  j j   n  |  j r |  j  r t d  nC |  j r |  j  r t d  |  j j	   n t d  |  j j	   d  S(   Ns&   
KeyboardInterrupt escaped interact()
s   keeping kernel alives#   owning kernel, cannot keep it alives   Shutting down kernel(
   t
   own_kernelt
   keepkernelR4   R  R9   R;   R   t   closeR   t   shutdown(   RN   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   mainloop  s     	
	

c         C  sH  | s | j    r! |  j   d Sx& |  j j j   rI |  j j j   q$ W|  j j | |  } t |  _ d |  _	 x |  j	 d k r |  j j
   r y |  j | d d Wqu t k
 r |  j |  qu t k
 r } | j t j k r   q qu Xqu Wx? |  j j
   r:y |  j | d d Wn t k
 r5q XPq Wt |  _ d S(   s  Run a complete IPython cell.

        Parameters
        ----------
        cell : str
          The code (including IPython code such as %magic functions) to run.
        store_history : bool
          If True, the raw and translated cell will be stored in IPython's
          history. For user code calling back into IPython's machinery, this
          should be set to False.
        Nt   busyt   idleR   g?(   t   isspaceR   R   t   shell_channelt	   msg_readyt   get_msgt   executeR4   t
   _executingt   _execution_statet   is_alivet   handle_input_requestR   R   t   errnot   EINTRt   handle_execute_replyR5   (   RN   R   R  R   t   e(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR    s.    
		!c         C  sI  |  j  j j d t d |  } | d j d d   | k rE|  j |  | d } | d } | d k rx |  j d  d  S| d	 k rx | j d
 g   D]~ } | d } | d k r t j | d d  q | d k r | d |  _	 q | d k r | j d t  |  _
 |  j   q q Wn | d k r+n  t | d d  |  _ n  d  S(   Nt   blockR   R   R   R\   t   statust   aborteds   Aborted
t   okt   payloadt   sourceR   t   datas
   text/plaint   set_next_inputRX   R   R
  t   errorR~   i   (   R   R  R  R5   R   R6   R   t   writeR   R  R
  R   t   intR~   (   RN   R   R   t   msgR\   R  t   itemR"  (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR  ?  s*    


c         C  s2  d } y" |  j j j d t d |  } Wn+ t k
 rU t d  t |  _ t d f SX| d j	 d d  | k r t d t
 |   t d f S| d j	 d	 d  } | d j	 d
 d  } | d k r t | f S| d k r t | f S| d k r t    n. | d k rt | f St d |  t | f Sd S(   sI  
        Wait for a repsonse from the kernel, and return two values:
            more? - (boolean) should the frontend ask for more input
            indent - an indent string to prefix the input
        Overloaded methods may want to examine the comeplete source. Its is
        in the self._source_lines_buffered list.
        R  R   s`   The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.Rd   R   R   sB   The kernel did not respond properly to an is_complete_request: %s.R\   R  R   t   completet
   incompletet   invalidt   unknowns:   The kernel sent an invalid is_complete_reply status: "%s".N(   R6   R   R  R  R4   R   R   R5   R   R   R   R   (   RN   R   R   R(  R  R   (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR   \  s,    	"
	



s   Whether to include output from clients
        other than this one sharing the same kernel.

        Outputs are not displayed until enter is pressed.
        s	   [remote] s   Prefix to add to outputs coming from clients other than this one.

        Only relevant if include_other_output is True.
        c         C  s    | d j  d |  j  |  j k S(   s-   Return whether a message is from this sessionR   Rn   (   R   Ro   (   RN   R(  (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt	   from_here  s    c         C  sB   |  j  |  } | d d k r- |  j o, | S|  j r: t S| Sd S(   s7   Return whether we should include a given output messaget   msg_typet   execute_inputN(   R.  t   include_other_outputR4   (   RN   R(  R.  (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   include_output  s    	c         C  s  x|  j  j j   r|  j  j j   } | d d } | d } | d k ri t | d d  d |  _ n  |  j |  r | d k r | d d	 |  _ q| d
 k r{| d d d k r|  j r t	 d d d t
 |  _ n  t	 | d d d d t j j   q| d d d k r|  j rGt	 d d t j d d t
 |  _ n  t	 | d d d t j d d t j j   qq| d k rf|  j rt	 d d d t
 |  _ n  t | d d  |  _ |  j |  st j j |  j  n  | d d } |  j |  d | k rq n  t j j   t j j   |  j   | d } d | k rYt	   n  t	 |  q| d k r| d d } |  j |  } | s|  j |  st j j |  j  n  d | k rt	 | d  qqq| d k rP| d }	 |  j |  st j j |  j  n  t j j d j |	 d   t j j |	 d d  q| d k r| d d rvt |  _ qt	 d d d q| d k rx, | d d D] }
 t	 |
 d t j qWqq q Wd S(   s   Process messages on the IOPub channel

           This method consumes and processes messages on the IOPub channel,
           such as stdout, stderr, execute_result and status.

           It only displays output that is caused by this session.
        t   headerR/  R   R0  R\   R~   i   R  t   execution_stateRi   RJ   t   stdouts   R   Rd   RX   t   stderrt   filet   execute_resultR#  s
   text/plains   
t   display_datas	   In [{}]: RP   t   clear_outputt   waitR%  t	   tracebackN(   R   t   iopub_channelR  R  R'  R~   R2  R  t   _pending_clearoutputR;   R5   R   R5  t   flushR6  R.  R&  t   other_output_prefixt   handle_rich_dataR   Rt   R4   (   RN   R   t   sub_msgR/  t   parentt   format_dictt	   text_reprR#  t   handledR\   t   frame(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR     sz    
		!	



t   pngt   jpegt   svgc         C  sL   xE |  j  D]: } | | k r
 | |  j k r
 |  j | |  rD t Sq
 q
 Wt S(   N(   t   mime_preferencet
   _imagemimet   handle_imageR4   R5   (   RN   R#  t   mime(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRA    s
    c         C  s5   t  |  d j |  j  d   } | r1 | | |  Sd  S(   Ns   handle_image_{0}(   R   Rt   t   image_handlerR6   (   RN   R#  RN  t   handler(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRM    s    c         C  s}   | d k r t  Sy d d l m } m } Wn t k
 r> t  SXt j | | j d   } | j t	 |   } | j
 |  S(   Ns	   image/pngs
   image/jpegi(   t   Imaget	   ImageShowt   ascii(   s	   image/pngs
   image/jpeg(   R5   Rh   RQ  RR  t   ImportErrort   base64t   decodestringt   encodet   openR   t   show(   RN   R#  RN  RQ  RR  t   rawt   img(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   handle_image_PIL  s    c   
      C  s   t  j | | j d   } |  j | } t d |  } g  |  j D] } | j |   ^ qB } t t j	 d  8 } t
 j | d t
 j d | d | }	 |	 j |  Wd  QX|	 j d k S(   NRS  Rt   t   wt   stdinR5  R6  i    (   RU  RV  RW  RL  t   dictt   stream_image_handlerRt   RX  R   t   devnullt
   subprocesst   Popent   PIPEt   communicatet
   returncode(
   RN   R#  RN  RZ  t   imageformatt   fmtR   t   argsRa  t   proc(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   handle_image_stream  s    %c         C  s   t  j | | j d   } |  j | } d j |  } t |   } t t j d  v } | j	 |  | j
   t d | j d |  } g  |  j D] }	 |	 j |   ^ q }
 t j |
 d | d | } Wd  QXWd  QX| d k S(	   NRS  s   tmp.{0}R]  R7  Rt   R5  R6  i    (   RU  RV  RW  RL  Rt   R	   RX  R   Ra  R&  R?  R_  RJ   t   tempfile_image_handlerRb  t   call(   RN   R#  RN  RZ  Rg  t   filenamet   fRa  Rh  R   Ri  t   rc(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   handle_image_tempfile  s    
%'c         C  s(   |  j  |  } | t k	 r$ t } n  | S(   N(   t   callable_image_handlerR5   R4   (   RN   R#  RN  t   res(    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   handle_image_callable,  s    	g?c           sB  |  j  j j d |  } |  j |  | | d j d  k r>t j t j      f d   } t j t j |  | d } | j d t  r t	 n t
 } zS y | | d  } Wn8 t k
 r d } n" t k
 r t j j d	  d
 SXWd
 t j t j    X|  j  j j   p%|  j  j j   s>|  j  j
 |  q>n  d
 S(   s%    Method to capture raw_input
        R   R   R   c           s     |  |  t   d  S(   N(   R9   (   t   sigRG  (   t   real_handler(    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt
   double_int=  s    R\   t   passwordR<   s   s   
N(   R   t   stdin_channelR  R   R   t   signalt	   getsignalt   SIGINTR5   R   R   R:   R9   R   R5  R&  R  R  (   RN   R   R   t   reqRw  R\   t   readt   raw_data(    (   Rv  s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyR  4  s&    
 		$N(   Rh   Ri   Rj   Rk   (N   R`   Ra   R5   t   readline_useR6   R   R  R   R  R>  R   R	  R4   R   R   R   R   R
   R   R   R   R   R   R   R   RO  R   R`  Rl  R   Rr  RK  R   R   R  R   t   managerR   Rr   Ro   Ru   t   tagR   RO   Ry   Rx   R   R   R   R   R   R{   R   R|   R   Rz   R   R   R  R   R  R  R  R  R   R1  R@  R.  R2  R   RL  RA  RM  R\  Rk  Rq  Rt  R  (    (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyRc   u   s   																						
								f						3%				V
						(\   Rb   t
   __future__R    RU  R  R   t   ioR   R   Rz  Rb  R   R   t   warningsR   t   queueR   RT  t   Queuet   zmqR   t   IPython.coreR   t   IPython.utils.py3compatR   R   t   ipython_genutils.tempdirR	   t	   traitletsR
   R   R   R   R   R   R   R   R   t   traitlets.configR   R   R   t
   zmqhistoryR   Rd   R   t   prompt_toolkit.completionR   R   t   prompt_toolkit.documentR   t   prompt_toolkit.enumsR   R   t   prompt_toolkit.filtersR   R   R   R   t   prompt_toolkit.historyR    t   prompt_toolkit.shortcutsR!   R"   R#   t   prompt_toolkit.interfaceR$   t"   prompt_toolkit.key_binding.managerR%   t#   prompt_toolkit.key_binding.vi_stateR&   t&   prompt_toolkit.key_binding.bindings.viR'   t   prompt_toolkit.keysR(   t   prompt_toolkit.layout.lexersR)   t   prompt_toolkit.stylesR*   t   pygments.stylesR+   t   pygments.lexersR,   t   pygments.utilR-   t   pygments.tokenR.   R6   RA   RK   RL   Rc   (    (    (    s6   lib/python2.7/site-packages/jupyter_console/ptshell.pyt   <module>   sZ   @" 	