
&9_[c           @  s  d  Z  d d l m Z d d l Z d d l Z d d l 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 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 m  Z  d d l! m" Z" d d l# m$ Z$ m% Z% d d l& m' Z' m( Z( m) Z) d d l* m+ Z+ d d l, m- Z- m. Z. m/ Z/ m0 Z0 d d l1 m2 Z2 d d l3 m4 Z4 d d l5 m6 Z6 m7 Z7 d d l8 m9 Z9 m: Z: d d l; m< Z< d d l= m> Z> d d l? m@ Z@ d d lA mB ZB mC ZC d d lD mE ZE d d lF mG ZG d d lH mI ZI mJ ZJ mK ZK d d lL mM ZM mN ZN d d lO mP ZP eQ   ZR d d l= m> Z> d e> f d     YZS i d  e@ jT 6d! e@ jU 6d" e@ jV 6d# e@ jW 6ZX i d$ e@ jT 6d% e@ jU 6d" e@ jV 6d# e@ jW 6ZY d&   ZZ xZ d' d( d) f D]C Z[ e\ e e[  Z] e] p@e^ e] d*  p@e] j_   rMe` Za Pn  q
Web Za d+ e jc k pjea Zd d, e f d-     YZe e	 jf ee  eg d. k ree jh   ji   n  d S(/   s/   IPython terminal interface using prompt_toolkiti(   t   print_functionN(   t   warn(   t   InteractiveShellt   InteractiveShellABC(   t   io(   t   PY3t   cast_unicode_py2t   inputt   string_types(   t   toggle_set_term_titlet   set_term_title(   t
   abbrev_cwd(
   t   Boolt   Unicodet   Dictt   Integert   observet   Instancet   Typet   defaultt   Enumt   Union(   t   Document(   t   DEFAULT_BUFFERt   EditingMode(   t   HasFocust	   Conditiont   IsDone(   t   InMemoryHistory(   t   create_prompt_applicationt   create_eventloopt   create_prompt_layoutt   create_output(   t   CommandLineInterface(   t   KeyBindingManager(   t   ConditionalProcessort!   HighlightMatchingBracketProcessor(   t   PygmentsStylet   DynamicStyle(   t   get_style_by_name(   t   Style(   t   Tokeni   (   t   TerminalPdbt   Pdb(   t   TerminalMagics(   t   get_inputhook_name_and_func(   t   Promptst   ClassicPromptst   RichPromptDisplayHook(   t   IPythonPTCompletert   IPythonPTLexer(   t   register_ipython_shortcutst   _NoStylec           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR4   *   s    s   #0000ffs   #0000ee bolds   #cc0000s   #bb0000 bolds   #00cc00s   #00bb00 boldc          C  ss   y* t  j d }  t s% |  j   }  n  |  SWn+ t k
 r= n t k
 rW t d  n Xt  j d k rk d Sd Sd  S(   Nt   EDITORsN   $EDITOR environment variable is not pure ASCII. Using platform default editor.t   posixt   vit   notepad(   t   ost   environR   t   decodet   KeyErrort   UnicodeErrorR   t   name(   t   ed(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   get_default_editor>   s    t   stdint   stdoutt   stderrt   isattyt   IPY_TEST_SIMPLE_PROMPTt   TerminalInteractiveShellc           B  sS  e  Z e d  d d j d e  Z d   Z d8 Z d8 Z	 d8 Z
 e e d d j d e  Z e d    Z e e d d j d e  Z e d d d	 j d e  Z e e d d
 j d e  Z e e d  e d e  g d d j d e  Z e d  e d  d     Z d   Z e d d  j d e  Z e e d d j d e  Z e e   d d j d e  Z  e e! d d j d e  Z" e# e!  Z$ e% d  d    Z& e d  d    Z' e% d  d    Z( e e d d j d e  Z) e* d9 d d d  d j d e  Z+ e e d d! j d e  Z, e e d d" j d e  Z- e d#  d8 d$   Z. d%   Z/ d&   Z0 d'   Z1 d(   Z2 d)   Z3 d*   Z4 d+   Z5 d,   Z6 d-   Z7 d.   Z8 d/   Z9 d0   Z: d8 Z; d1   Z< e= d2  Z> e= d3  Z? d8 Z@ d4   ZA d8 ZB d8 d5  ZC eD jE ZF d6   ZG d8 ZH d7   ZI RS(:   i   t   helpsM   Number of line at the bottom of the screen to reserve for the completion menut   configc         C  s   |  j    d  S(   N(   t   _update_layout(   t   selft   oldt   new(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _space_for_menu_changedc   s    s  Use `raw_input` for the REPL, without completion and prompt colors.

            Useful when controlling IPython as a subprocess, and piping STDIN/OUT/ERR. Known usage are:
            IPython own testing machinery, and emacs inferior-shell integration through elpy.

            This mode default to `True` if the `IPY_TEST_SIMPLE_PROMPT`
            environment variable is set, or the current terminal is not a tty.

            c         C  s   |  j  r t St S(   N(   t   simple_promptR+   R*   (   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   debugger_clsv   s    s   
        Set to confirm when you try to exit IPython with an EOF (Control-D
        in Unix, Control-Z/Enter in Windows). By typing 'exit' or 'quit',
        you can force a direct exit without any confirmation.t   emacss5   Shortcut style to use at the prompt. 'vi' or 'emacs'.s"   Enable mouse support in the promptt   legacyt   klasss   The name or class of a Pygments style to use for syntax
        highlighting. To see available styles, run `pygmentize -L styles`.t   highlighting_stylet   colorsc         C  s   |  j    d  S(   N(   t   refresh_style(   RL   t   change(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _highlighting_style_changed   s    c         C  s   |  j  |  j  |  _ d  S(   N(   t   _make_style_from_name_or_clsRU   t   _style(   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRW      s    s0   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"s?   Set the editor used by IPython (default to $EDITOR/vi/notepad).s6   Class used to generate Prompt token for prompt_toolkitt   promptsc         C  s   |  j  |   S(   N(   t   prompts_class(   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _prompts_default   s    c         C  s   |  j    d  S(   N(   RK   (   RL   RX   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _   s    t   displayhook_classc         C  s   t  S(   N(   R0   (   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _displayhook_class_default   s    s$   Automatically set the terminal titlet   columnt   multicolumnt   readlinelikes   Options for displaying tab completions, 'column', 'multicolumn', and 'readlinelike'. These options are for `prompt_toolkit`, see `prompt_toolkit` documentation for more information.t   default_values   Highlight matching brackets.s   Enable vi (v) or Emacs (C-X C-E) shortcuts to open an external editor. This is in addition to the F2 binding, which is always enabled.t
   term_titlec         C  s5   |  j  r' t t  t d t    n
 t t  d  S(   Ns	   IPython: (   Rf   R	   t   TrueR
   R   t   False(   RL   RX   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   init_term_title   s    	
c         C  s5   t  t |   j   d g |  j _ t |  j j _ d  S(   Ns
   text/plain(   t   superRH   t   init_display_formattert   display_formattert   active_typesRh   t   ipython_display_formattert   enabled(   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRk      s    c   
        s    j  r%   f d   } |   _ d  St j d   j  } t | j    t   } d } x`   j j	   j
 d t D]C \ } } } | j   } | ru | | k ru | j |  | } qu qu W  j   j    _ t   f d      _ t t   j j    }   f d   }	 t d | d | j d	 | d
 t d   d |	  d t d   j d   j   j      _ t   j    _ t   j d   j d t  d   j!    _" d  S(   Nc            s     j  }  d j d     j j   D  } d j d     j j   D  } x5 |  j   r t t |   } |  j |  | } qP W|  j	   S(   Nt    c         s  s   |  ] } | d  Vq d S(   i   N(    (   t   .0t   x(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pys	   <genexpr>   s    c         s  s   |  ] } | d  Vq d S(   i   N(    (   Rq   Rr   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pys	   <genexpr>   s    (
   t   input_splittert   joinR\   t   in_prompt_tokenst   continuation_prompt_tokenst   push_accepts_moreR   R   t   pusht   source_reset(   t   ispt   prompt_textt   prompt_continuationt   line(   RL   (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   prompt   s    	""
t   enable_open_in_editoru    t   include_latestc             s     j  S(   N(   R[   (    (   RL   (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   <lambda>   s    c            s     j  j |    S(   N(   t   pt_clit   patch_stdout_context(   t   kwargs(   RL   (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   patch_stdout  s    t   editing_modet   key_bindings_registryt   historyt	   completert   shellR   t   enable_history_searcht   stylet   mouse_supportt	   eventloopt   outputt
   true_color(#   RP   t   prompt_for_codeR"   t
   for_promptt   extra_open_editor_shortcutsR3   t   registryR   t   history_managert   get_tailt   history_load_lengthRg   t   rstript   appendRZ   RU   R[   R&   R   t   getattrR   R   t   upperR   R1   R   t   _layout_optionst   _pt_appR   t	   inputhookt
   _eventloopR!   R    R   R   (
   RL   R~   t	   kbmanagerR   t	   last_cellt   __t   ___t   cellR   R   (    (   RL   s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   init_prompt_toolkit_cli   sB    								c         C  s  i  } | d k rl|  j  j   } | d k rB t d  } t } q| d k rc t } t d  } q| d k r?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 6d t j 6d t j 6d t j 6d t j 6 t j d k ri| j i d t j 6d t j 6d t j 6d t j 6 qiq| d k rZt } i  } qt d |   nR t | t  rt |  } n | } i d t j 6d t j 6d t j 6d t j 6} | j |  j  t j d | d |  } | S(   s   
        Small wrapper that make an IPython compatible style from a style name

        We need that to add style for prompt ... etc.
        RS   t   linuxt   monokait   lightbgt   pastiet   neutralR   s   #007700t	   noinherits   #BB6622s   #2080D0s   bold #2080D0s   #009900s   #00ff00 bolds   #990000s   #ff0000 boldt   nts   #ansidarkgreens   #ansigreen bolds   #ansidarkreds   #ansired boldt   nocolors   Got unknown colors: t   pygments_style_clst
   style_dict(   RV   t   lowerR'   t   _style_overrides_linuxt   _style_overrides_light_bgt   updateR)   t   Numbert   Operatort   Stringt   Namet   Functiont   Classt	   Namespacet   Promptt	   PromptNumt	   OutPromptt   OutPromptNumR;   R@   R4   t
   ValueErrort
   isinstanceR   t   highlighting_style_overridesR%   t   from_defaults(   RL   t   name_or_clst   style_overridesRS   t	   style_clsR   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRZ     sX    		





	


	


	c      	     s   i t    d 6  j d 6  j j d 6  j j d 6t d 6  j d k d 6t d t d	 d
  d t	 t
  t   @t   f d    @ g d 6S(   s\   
        Return the current layout option for the current Terminal InteractiveShell
        t   lexert   reserve_space_for_menut   get_prompt_tokenst   get_continuation_tokenst	   multilineRc   t   display_completions_in_columnst	   processort   charss   [](){}t   filterc           s     j  S(   N(   t   highlight_matching_brackets(   t   cli(   RL   (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR   g  s    t   extra_input_processors(   R2   t   space_for_menuR\   Ru   Rv   Rg   t   display_completionsR#   R$   R   R   R   R   (   RL   (    (   RL   s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR   V  s    

c         C  s(   |  j  r$ t |  j     |  j  _ n  d S(   s   
        Ask for a re computation of the application layout, if for example ,
        some configuration options have changed.
        N(   R   R   R   t   layout(   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRK   j  s    	c         C  s%   |  j  j d |  j d t  } | j S(   Nt   pre_runt   reset_current_buffer(   R   t   runt
   pre_promptRg   t   text(   RL   t   document(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR   r  s    c         C  s   t  j d	 k r d  Sd d  l } t r2 | j   n` d d l m } m } m } d | f d     Y} | |  } | |  } | j d | d |  d  S(
   Ni   i   i(   t   TextStreamWrappert   stdout_text_transcodedt   stderr_text_transcodedt   LenientStrStreamWrapperc           B  s   e  Z d    Z RS(   c         S  s;   t  | t  r' | j |  j d  } n  |  j j |  d  S(   Nt   replace(   R   t   bytesR=   t   encodingt   baset   write(   RL   t   s(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR     s    (   R5   R6   R   (    (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR     s   RD   RE   (   i   i   (	   t   syst   version_infot   win_unicode_consoleR   t   enablet   win_unicode_console.streamsR   R   R   (   RL   R   R   R   R   R   t   stdout_text_strt   stderr_text_str(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   enable_win_unicode_consolew  s    c         C  s   t  j d d h k r d  S|  j   d d  l } | j   t j   ? t j d t  t	 j
 t  j  t	 _ t	 j
 t  j  t	 _ Wd  QXd  S(   Nt   win32R   it   ignore(   R   t   platformR   t   coloramat   initt   warningst   catch_warningst   simplefiltert   DeprecationWarningR   t   IOStreamRD   RE   (   RL   R   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   init_io  s    

c         C  s$   t  t |   j   |  j t  d  S(   N(   Rj   RH   t   init_magicst   register_magicsR,   (   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR     s    c         C  sY   t  t |   j   t j d k rU x0 d d d d g D] } |  j j | |  q5 Wn  d  S(   NR8   t   cleart   moret   lesst   man(   Rj   RH   t
   init_aliasR;   R@   t   alias_managert   soft_define_alias(   RL   t   cmd(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR     s    c         O  sF   t  t |   j | |   |  j   |  j   t |  _ t   |  _ d  S(   N(	   Rj   RH   t   __init__R   Ri   Rg   t   keep_runningR   t   debugger_history(   RL   t   argsR   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR    s
    

	c         C  s   t  |  _ d  S(   N(   Rh   R  (   RL   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.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   bufferR   (    (   R   RL   (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   set_doc  s    t   pre_run_callables(   t   rl_next_inputR   t   hasattrR   R
  R   t   None(   RL   R	  (    (   R   RL   s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR     s    	c         C  s   | t  k	 r" t d t d d n  t |  _ x |  j r t |  j d d y |  j   } Wn= t k
 r |  j	 s |  j
 d d d  r |  j   q q. X| r. |  j | d	 t q. q. Wd  S(
   Nsc   interact `display_banner` argument is deprecated since IPython 5.0. Call `show_banner()` if needed.t
   stackleveli   t   endRp   s#   Do you really want to exit ([y]/n)?t   yt   nt   store_history(   t   DISPLAY_BANNER_DEPRECATEDR   R   Rg   R  t   printt   separate_inR   t   EOFErrort   confirm_exitt
   ask_yes_noR  t   run_cell(   RL   t   display_bannert   code(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   interact  s    	
c         C  s   | t  k	 r" t d t d d n  xm t r z@ y |  j   PWn* t k
 ri } t d t |  j  n XWd  t	 |  d  r |  j
 j   n  Xq% Wd  S(   Nsc   mainloop `display_banner` argument is deprecated since IPython 5.0. Call `show_banner()` if needed.R  i   s   
%s escaped interact()
R   (   R  R   R   Rg   R  t   KeyboardInterruptR  t   typeR5   R  R   t   stop(   RL   R  t   e(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   mainloop  s    	 
c         C  s#   |  j  d  k	 r |  j  |  n  d  S(   N(   t
   _inputhookR  (   RL   t   context(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR     s    c         C  s5   | r! t  |  \ |  _ |  _ n d  |  _ |  _ d  S(   N(   R-   t   active_eventloopR"  R  (   RL   t   gui(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt
   enable_gui  s    c         C  sr   |  j  s d S|  j j   } |  j rB |  j j |  t |  n, d j d   | D  } t | | d d d S(   s>   Overridden from the parent class to use fancy rewriting promptNRp   c         s  s   |  ] \ } } | Vq d  S(   N(    (   Rq   t   tR   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pys	   <genexpr>  s    t   sep(   t   show_rewritten_inputR\   t   rewrite_prompt_tokensR   t   print_tokensR  Rt   (   RL   R  t   tokensR~   (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   auto_rewrite_input  s    		c         C  sS   | r$ |  j  |  _ t |   |  _  n! |  j rE |  j |  _  d |  _ n  |  j   d S(   s+   Switch prompts to classic for %doctest_modeN(   R\   t   _prompts_beforeR/   R  RK   (   RL   t   mode(    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   switch_doctest_mode  s    	N(   Rb   Rc   Rd   (J   R5   R6   R   t   tagRg   R   RO   R  R   R  R   R   t   _use_simple_promptRP   t   propertyRQ   R  R   R   Rh   R   R   R   R(   RU   R   RY   RW   R   R   R   RB   t   editorR.   R]   R   R\   R   R^   R_   Ra   Rf   R   R   R   R   Ri   Rk   R   RZ   R   RK   R   R   R   R   R   R  R  R  R   R  R  R!  R"  R   R$  R&  R   t
   system_rawt   systemR-  R.  R0  (    (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRH   ^   s   																												9	@														t   __main__(j   t   __doc__t
   __future__R    R;   R   R   R   t   IPython.core.interactiveshellR   R   t   IPython.utilsR   t   IPython.utils.py3compatR   R   R   R   t   IPython.utils.terminalR	   R
   t   IPython.utils.processR   t	   traitletsR   R   R   R   R   R   R   R   R   R   t   prompt_toolkit.documentR   t   prompt_toolkit.enumsR   R   t   prompt_toolkit.filtersR   R   R   t   prompt_toolkit.historyR   t   prompt_toolkit.shortcutsR   R   R   R    t   prompt_toolkit.interfaceR!   t"   prompt_toolkit.key_binding.managerR"   t    prompt_toolkit.layout.processorsR#   R$   t   prompt_toolkit.stylesR%   R&   t   pygments.stylesR'   t   pygments.styleR(   t   pygments.tokenR)   t   debuggerR*   R+   t   magicsR,   t   pt_inputhooksR-   R\   R.   R/   R0   t   ptutilsR1   R2   t	   shortcutsR3   t   objectR  R4   R   R   R   R   R   R   RB   t   _nameR   t   _streamR  RF   Rh   t   _is_ttyRg   R<   R2  RH   t   registerR5   t   instanceR  (    (    (    s@   lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   <module>   sn   "F"	





	$ 