ó
æNXc           @  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 m Z d d l	 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 d d l m Z d d l 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' m( Z( m) Z) d „  Z* e j+ e, d „ Z- e d e f d „  ƒ  Yƒ Z. d e f d „  ƒ  YZ/ e j0 e/ ƒ d S(   s:   Subclass of InteractiveShell for terminal based frontends.iÿÿÿÿ(   t   print_functionN(   t   TryNextt
   UsageError(   t   interactive_usage(   t   IPythonInputSplitter(   t   InteractiveShellt   InteractiveShellABC(   t   Magicst   magics_classt
   line_magic(   t   ClipboardEmpty(   t   get_stream_enc(   t	   py3compat(   t   toggle_set_term_titlet   set_term_title(   t
   abbrev_cwd(   t   warnt   error(   t   num_ini_spacest   SListt   strip_email_quotes(   t   Integert   CBoolt   Unicodec          C  sv   y- t  j d }  t j s( |  j ƒ  }  n  |  SWn+ t k
 r@ n t k
 rZ t d ƒ n Xt  j d k rn 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   PY3t   decodet   KeyErrort   UnicodeErrorR   t   name(   t   ed(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   get_default_editor(   s    	c         c  s   | s t  d |  ƒ d } n d } xW t r| y. t j | | ƒ ƒ } | |  k rT d S| VWq& t k
 rx t  d ƒ d SXq& Wd S(   sH    Yield pasted lines until the user enters the given sentinel value.
    sA   Pasting code; enter '%s' alone on the line to stop or use Ctrl-D.t   :t    Ns   <EOF>(   t   printt   TrueR   t   str_to_unicodet   EOFError(   t   sentinelt   l_inputt   quiett   promptt   l(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   get_pasted_lines9   s    			
t   TerminalMagicsc           B  s†   e  Z d  „  Z d „  Z d „  Z d d „ Z e d d „ ƒ Z e d d „ ƒ Z e d d „ ƒ Z	 e
 j d	 k r„ e d
 „  ƒ Z n  RS(   c         C  s&   t  t |  ƒ j | ƒ t ƒ  |  _ d  S(   N(   t   superR1   t   __init__R   t   input_splitter(   t   selft   shell(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR3   T   s    c         C  s†   | r3 t  | j ƒ  ƒ |  j j | <t d | ƒ nO |  j | ƒ } | |  j j d <t |  j _ z |  j j | ƒ Wd t	 |  j _ Xd S(   sM    Execute a block, or store it in a variable, per the user's request.
        s   Block assigned to '%s't   pasted_blockN(
   R   t
   splitlinesR6   t   user_nsR'   t   preclean_inputR(   t   using_paste_magicst   run_cellt   False(   R5   t   blockR"   t   b(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   store_or_executeX   s    c         C  sG   | j  ƒ  } x% | r3 | d j ƒ  r3 | d } q Wt d j | ƒ ƒ S(   Ni    i   s   
(   R8   t   stripR   t   join(   R5   R>   t   lines(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR:   h   s    R7   c         C  s   |  j  j j | ƒ } | d k r0 t d ƒ ‚ n  t | t j ƒ sQ t d ƒ ‚ n  t d | j	 d d ƒ d t
 | ƒ f ƒ |  j  j | ƒ d S(   s,    Rerun a previously pasted command.
        s"   No previous pasted block availables6   Variable 'pasted_block' is not a string, can't executes   Re-executing '%s...' (%d chars)s   
i   i    N(   R6   R9   t   gett   NoneR   t
   isinstanceR   t   string_typesR'   t   splitt   lenR<   (   R5   R"   R?   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   rerun_pastedn   s    *R&   c         C  s.   |  j  j ƒ  t d d d g |  j  j ƒ d S(   s(   Toggle autoindent on/off (if available).s   Automatic indentation is:t   OFFt   ONN(   R6   t   set_autoindentR'   t
   autoindent(   R5   t   parameter_s(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRN   }   s    c         C  s…   |  j  | d d d ƒ\ } } d | k r8 |  j ƒ  d Sd | k } | j d d ƒ } d	 j t | d
 | ƒƒ } |  j | | ƒ d S(   s–  Paste & execute a pre-formatted code block from clipboard.

        You must terminate the block with '--' (two minus-signs) or Ctrl-D
        alone on the line. You can also provide your own sentinel with '%paste
        -s %%' ('%%' is the new sentinel for this operation).

        The block is dedented prior to execution to enable execution of method
        definitions. '>' and '+' characters at the beginning of a line are
        ignored, to allow pasting directly from e-mails, diff files and
        doctests (the '...' continuation prompt is also stripped).  The
        executed block is also assigned to variable named 'pasted_block' for
        later editing with '%edit pasted_block'.

        You can also pass a variable name as an argument, e.g. '%cpaste foo'.
        This assigns the pasted block to variable 'foo' as string, without
        dedenting or executing it (preceding >>> and + is still stripped)

        '%cpaste -r' re-executes the block previously entered by cpaste.
        '%cpaste -q' suppresses any additional output messages.

        Do not be alarmed by garbled output on Windows (it's a readline bug).
        Just press enter and type -- (and press enter again) and the block
        will be what was just pasted.

        IPython statements (magics, shell escapes) are not supported (yet).

        See also
        --------
        paste: automatically pull code from clipboard.

        Examples
        --------
        ::

          In [8]: %cpaste
          Pasting code; enter '--' alone on the line to stop.
          :>>> a = ["world!", "Hello"]
          :>>> print " ".join(sorted(a))
          :--
          Hello world!
        s   rqs:t   modet   stringt   rNt   qt   su   --s   
R-   (   t   parse_optionsRJ   RD   RB   R0   R@   (   R5   RO   t   optsR"   R-   R+   R>   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   cpaste„   s    +
c         C  s  |  j  | d d d ƒ\ } } d | k r8 |  j ƒ  d Sy |  j j j ƒ  } Wn` t k
 r” } t | d ƒ } | r† t | d ƒ n
 t d ƒ d St k
 r° t	 d	 ƒ ‚ n Xd
 | k r|  j j
 } | |  j j | ƒ ƒ | j d ƒ sû | d ƒ n  | d ƒ n  |  j | | ƒ d S(   sä  Paste & execute a pre-formatted code block from clipboard.

        The text is pulled directly from the clipboard without user
        intervention and printed back on the screen before execution (unless
        the -q flag is given to force quiet mode).

        The block is dedented prior to execution to enable execution of method
        definitions. '>' and '+' characters at the beginning of a line are
        ignored, to allow pasting directly from e-mails, diff files and
        doctests (the '...' continuation prompt is also stripped).  The
        executed block is also assigned to variable named 'pasted_block' for
        later editing with '%edit pasted_block'.

        You can also pass a variable name as an argument, e.g. '%paste foo'.
        This assigns the pasted block to variable 'foo' as string, without
        executing it (preceding >>> and + is still stripped).

        Options:

          -r: re-executes the block previously entered by cpaste.

          -q: quiet mode: do not echo the pasted text back to the terminal.

        IPython statements (magics, shell escapes) are not supported (yet).

        See also
        --------
        cpaste: manually paste code into terminal until you mark its end.
        t   rqRP   RQ   RR   Nt   argsi    s&   Could not get text from the clipboard.s!   The clipboard appears to be emptyRS   s   
s   ## -- End pasted text --
(   RU   RJ   R6   t   hookst   clipboard_getR   t   getattrR   R
   R   t   writet
   pycolorizet   endswithR@   (   R5   RO   RV   R"   R>   t   clipboard_exct   messageR]   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   pasteº   s*    

t   win32c         C  s   t  j d ƒ d S(   s   Clear screen.
            t   clsN(   R   t   system(   R5   RT   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRd   õ   s    (   t   __name__t
   __module__R3   R@   R:   RJ   R	   RN   RW   Rb   t   syst   platformRd   (    (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR1   R   s   			59t   TerminalInteractiveShellc           B  s‹  e  Z e e d  e d d ƒZ e e d  e d d ƒZ e e ƒ Z e e ƒ Z e e ƒ Z	 e
 e ƒ  d  e d d ƒZ e
 d d  e d d ƒZ e d d  e d d ƒZ e e d  e d d	 ƒZ e
 e ƒ Z e e ƒ Z e d d d
 „ ƒ Z e j Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d d „ Z  d „  Z! d d „ Z" d d „ Z# d „  Z$ d „  Z% d „  Z& d „  Z' d „  Z( d „  Z) RS(   t   configt   helps)   auto editing of files with syntax errors.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.s?   Set the editor used by IPython (default to $EDITOR/vi/notepad).t   lesss(   The shell program to be used for paging.i    sb  Number of lines of your screen, used to control printing of very
        long strings.  Strings longer than this number of lines will be sent
        through a pager instead of directly printed.  The default value for
        this is 0, which means IPython will auto-detect your screen size every
        time it needs to print certain potentially long strings (this doesn't
        change the behavior of the 'print' keyword, it's only triggered
        internally). If for some reason this isn't working well (it needs
        curses support), specify it yourself. Otherwise don't change the
        default.s'   Enable auto setting the terminal title.c         C  sK   d d l  m } y | |  | ƒ SWn# t k
 rF } t d | ƒ ‚ n Xd S(   s0   Switch amongst GUI input hooks by name.
        iÿÿÿÿ(   t
   enable_guis   %sN(   t   IPython.lib.inputhookRn   t
   ValueErrorR   (   t   guit   appt   real_enable_guit   e(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRn   ,  s
    c         C  s&   t  t |  ƒ j ƒ  d g |  j _ d  S(   Ns
   text/plain(   R2   Rj   t   init_display_formattert   display_formattert   active_types(   R5   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRu   =  s    c         C  s8   |  j  d k r d S|  j j d ƒ d } |  j  | Sd  S(   Ni    s   
i   (   t   screen_lengtht   separate_int   count(   R5   t   num_lines_bot(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   usable_screen_lengthF  s    c         C  s   |  j  ƒ  d  S(   N(   t   init_term_title(   R5   R"   t	   new_value(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _term_title_changedN  s    c         C  s5   |  j  r' t t ƒ t d t ƒ  ƒ n
 t t ƒ d  S(   Ns	   IPython: (   t
   term_titleR   R(   R   R   R=   (   R5   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR}   Q  s    	
c         C  sk   t  t |  ƒ j ƒ  t j d k r7 d d d d	 g } n g  } x' | D] \ } } |  j j | | ƒ qD Wd  S(
   NR   t   cleart   moreRm   t   man(   s   clears   clear(   s   mores   more(   Rm   Rm   (   s   mans   man(   R2   Rj   t
   init_aliasR   R"   t   alias_managert   soft_define_alias(   R5   t   aliasesR"   t   cmd(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR„   ]  s    	c         C  s`   |  j  Q |  j A x9 y |  j d | ƒ PWq t k
 rL |  j d ƒ q Xq Wd QXWd QXd S(   sŽ   Start the mainloop.

        If an optional banner argument is given, it will override the
        internally created default banner.
        t   display_banners!   
KeyboardInterrupt in interact()
N(   t   builtin_trapt   display_trapt   interactt   KeyboardInterruptR]   (   R5   R‰   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   mainloopr  s    
 
c         C  sÑ   |  j  s |  j r | St |  j d ƒ s. | S| j ƒ  s> | S|  j j ƒ  } | | k r] | Sx0 t | | ƒ D] } |  j j | | d ƒ qn Wt t	 j
 d ƒ } |  j j t j | j ƒ  | ƒ ƒ |  j j ƒ  S(   s1   Store multiple lines as a single entry in historyt   remove_history_itemi   s   utf-8(   t   has_readlinet   multiline_historyt   hasattrt   readlinet   rstript   get_current_history_lengtht   rangeR   R   Rh   t   stdint   add_historyR   t   unicode_to_str(   R5   t
   source_rawt   hlen_before_cellt   hlent   it   stdin_encoding(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   _replace_rlhist_multiline‡  s    
c         C  sñ  |  j  r d S| d k r% |  j } n  t | t j ƒ rG |  j | ƒ n | rZ |  j ƒ  n  t } |  j r‹ |  j	 |  j
 ƒ |  j j ƒ  } n d } xP|  j  sã|  j j ƒ  | rò y |  j j d ƒ } Wn |  j ƒ  n X|  j r#t |  _ q#n1 y |  j |  j j d ƒ } Wn |  j ƒ  n Xy5 |  j | ƒ } |  j  rBPn  |  j rWt |  _ n  Wné t k
 rÁyB |  j d |  j ƒ  ƒ |  j j ƒ  } |  j | | ƒ } t } Wqàt k
 r½qàXq” t k
 r|  j rüt |  _ |  j rü|  j	 d ƒ qün  |  j d ƒ |  j ƒ  q” t j  k
 r3t! d ƒ q” |  j ƒ  q” Xy# |  j j" | ƒ |  j j# ƒ  } Wn t$ k
 r€t } n X|  j% j& r£|  j' r£|  j( ƒ  n  | s” |  j j ƒ  } |  j) | d t ƒ|  j | | ƒ } q” q” Wt |  _  d S(   s/   Closely emulate the interactive Python console.Ni    t   in2t   ins   
sÏ   The Python debugger has exited with a BdbQuit exception.
Because of how pdb handles the stack, it is impossible
for IPython to properly format this particular exception.
IPython will resume normal operation.t   store_history(*   t   exit_nowRE   R‰   RF   R   RG   t   show_bannerR=   R   t   readline_startup_hookt   pre_readlineR“   R•   RZ   t   pre_prompt_hookt   prompt_managert   rendert   showtracebackRN   R(   t   rl_do_indentRy   t	   raw_inputR   R]   t   get_exception_onlyR4   t	   raw_resetRŸ   R*   t   exitt   bdbt   BdbQuitR   t   pusht   push_accepts_moret   SyntaxErrort   SyntaxTBt   last_syntax_errort   autoedit_syntaxt   edit_syntax_errorR<   (   R5   R‰   R‚   t   hlen_b4_cellR.   t   lineRš   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRŒ   ¢  s€    					
			
	R&   c         C  s’   t  j | ƒ } y t  j |  j | ƒ ƒ } Wn& t k
 rS t d ƒ |  j ƒ  d SX|  j rŽ t | ƒ |  j	 k rŽ | |  j	 } d |  _	 qŽ n  | S(   s-  Write a prompt and read a line.

        The returned line does not include the trailing newline.
        When the user enters the EOF key sequence, EOFError is raised.

        Parameters
        ----------

        prompt : str, optional
          A string to be printed to prompt the user.
        sc   
********
You or a %run:ed script called sys.stdin.close() or sys.stdout.close()!
Exiting IPython!
R&   i    (
   R   t   cast_bytes_py2t   cast_unicode_py2t   raw_input_originalRp   R   t   ask_exitRN   R   t   indent_current_nsp(   R5   R.   Rº   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR¬      s    

	c         C  s³   x¬ |  j  j r® |  j  j ƒ  } |  j | ƒ s1 d Sy |  j | j |  j ƒ Wn |  j ƒ  q Xy8 t | j ƒ } z t	 j
 | j ƒ  ƒ Wd | j ƒ  XWq |  j ƒ  q Xq Wd S(   sˆ   The bottom half of the syntax error handler called in the main loop.

        Loop until syntax error is fixed or user cancels.
        N(   Rµ   R¶   t   clear_err_statet   _should_recompilet   safe_execfilet   filenameR9   Rª   t   openRh   t   displayhookt   readt   close(   R5   t   errt   f(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR¸   %  s    c         C  s­   | j  d k r t Sy$ |  j r6 |  j d d ƒ r6 t SWn t k
 rK t SXd „  } y5 |  j j | j  | | j ƒ | | j	 ƒ | j
 ƒ Wn t k
 r¨ t d	 ƒ t SXt S(   s%   Utility routine for edit_syntax_errors   <ipython console>s   <input>s   <string>s	   <console>s   <BackgroundJob compilation>s0   Return to editor to correct syntax error? [Y/n] t   yc         S  s'   y t  |  ƒ SWn t k
 r" d SXd  S(   Ni    (   t   intt	   TypeError(   t   x(    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   int0Q  s    s   Could not open editorN(   s   <ipython console>s   <input>s   <string>s	   <console>s   <BackgroundJob compilation>N(   RÃ   RE   R=   R·   t
   ask_yes_noR*   RZ   t   fix_error_editort   linenot   offsett   msgR   R   R(   (   R5   Rt   RÎ   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRÁ   A  s&     			
	&
c         C  s   t  |  _ d S(   s@    Ask the shell to exit. Can be overiden and used as a callback. N(   R(   R£   (   R5   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR¾   c  s    c         C  s9   |  j  r+ |  j d d ƒ r5 |  j ƒ  q5 n
 |  j ƒ  d S(   sJ   Handle interactive exit.

        This method calls the ask_exit callback.s#   Do you really want to exit ([y]/n)?RÊ   N(   t   confirm_exitRÏ   R¾   (   R5   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR¯   g  s    	c         C  s$   t  t |  ƒ j ƒ  |  j t ƒ d  S(   N(   R2   Rj   t   init_magicst   register_magicsR1   (   R5   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRÕ   u  s    c         C  s-   t  t |  ƒ j ƒ  |  j s) t d ƒ n  d  S(   NsS   If you want to paste code into IPython, try the %paste and %cpaste magic functions.(   R2   Rj   t   showindentationerrorR;   R'   (   R5   (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyR×   y  s    	N(*   Rf   Rg   R   R=   R(   R·   RÔ   R‰   t   embeddedt   embedded_activeR   R$   t   editort   pagerR   Rx   R€   R   t   usageR;   t   staticmethodRE   Rn   R   t
   system_rawRe   Ru   t   propertyR|   R   R}   R„   RŽ   RŸ   RŒ   R¬   R¸   RÁ   R¾   R¯   RÕ   R×   (    (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyRj   ÿ   sF   				
		
							^%		"			(1   t   __doc__t
   __future__R    R°   R   Rh   t   IPython.core.errorR   R   t   IPython.core.usageR   t   IPython.core.inputsplitterR   t   IPython.core.interactiveshellR   R   t   IPython.core.magicR   R   R	   t   IPython.lib.clipboardR
   t   IPython.utils.encodingR   t   IPython.utilsR   t   IPython.utils.terminalR   R   t   IPython.utils.processR   t   IPython.utils.warnR   R   t   IPython.utils.textR   R   R   t	   traitletsR   R   R   R$   t   inputR=   R0   R1   Rj   t   register(    (    (    sY   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/terminal/interactiveshell.pyt   <module>   s0   	¬ÿ ‚