<s> """<STR_LIT>""" <EOL> import sys <EOL> import pydoc <EOL> import os <EOL> import re <EOL> import builtins <EOL> from IPython . core . iplib import InteractiveShell <EOL> from IPython . kernel . core . redirector_output_trap import RedirectorOutputTrap <EOL> from IPython . kernel . core . sync_traceback_trap import SyncTracebackTrap <EOL> import IPython . utils . io <EOL> from linefrontendbase import LineFrontEndBase , common_prefix <EOL> def mk_system_call ( system_call_function , command ) : <EOL> """<STR_LIT>""" <EOL> def my_system_call ( args ) : <EOL> system_call_function ( "<STR_LIT>" % ( command , args ) ) <EOL> my_system_call . __doc__ = "<STR_LIT>" % command <EOL> return my_system_call <EOL> class PrefilterFrontEnd ( LineFrontEndBase ) : <EOL> """<STR_LIT>""" <EOL> debug = False <EOL> def __init__ ( self , ipython0 = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> LineFrontEndBase . __init__ ( self , * args , ** kwargs ) <EOL> self . shell . output_trap = RedirectorOutputTrap ( <EOL> out_callback = self . write , <EOL> err_callback = self . write , <EOL> ) <EOL> self . shell . traceback_trap = SyncTracebackTrap ( <EOL> formatters = self . shell . traceback_trap . formatters , <EOL> ) <EOL> self . save_output_hooks ( ) <EOL> if ipython0 is None : <EOL> def my_rawinput ( x = None ) : <EOL> return '<STR_LIT:\n>' <EOL> old_rawinput = builtins . raw_input <EOL> builtins . raw_input = my_rawinput <EOL> ipython0 = InteractiveShell ( <EOL> parent = None , user_ns = self . shell . user_ns , <EOL> user_global_ns = self . shell . user_global_ns <EOL> ) <EOL> builtins . raw_input = old_rawinput <EOL> self . ipython0 = ipython0 <EOL> self . ipython0 . set_hook ( '<STR_LIT>' , <EOL> lambda s , string : self . write ( "<STR_LIT:\n>" + string ) ) <EOL> self . ipython0 . write = self . write <EOL> self . _ip = _ip = self . ipython0 <EOL> self . _ip . system = self . system_call <EOL> if not sys . platform . startswith ( '<STR_LIT>' ) : <EOL> self . ipython0 . magic_ls = mk_system_call ( self . system_call , <EOL> '<STR_LIT>' ) <EOL> self . release_output ( ) <EOL> if not '<STR_LIT>' in kwargs and self . banner is None : <EOL> self . banner = self . ipython0 . banner <EOL> self . start ( ) <EOL> def show_traceback ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ipython0 . showtraceback ( tb_offset = - <NUM_LIT:1> ) <EOL> self . release_output ( ) <EOL> def execute ( self , python_string , raw_string = None ) : <EOL> if self . debug : <EOL> print ( '<STR_LIT>' , repr ( python_string ) ) <EOL> self . capture_output ( ) <EOL> LineFrontEndBase . execute ( self , python_string , <EOL> raw_string = raw_string ) <EOL> self . release_output ( ) <EOL> def save_output_hooks ( self ) : <EOL> """<STR_LIT>""" <EOL> self . __old_cout_write = Term . cout . write <EOL> self . __old_cerr_write = Term . cerr . write <EOL> self . __old_stdout = sys . stdout <EOL> self . __old_stderr = sys . stderr <EOL> self . __old_help_output = pydoc . help . output <EOL> self . __old_display_hook = sys . displayhook <EOL> def capture_output ( self ) : <EOL> """<STR_LIT>""" <EOL> self . save_output_hooks ( ) <EOL> Term . cout . write = self . write <EOL> Term . cerr . write = self . write <EOL> sys . stdout = Term . cout <EOL> sys . stderr = Term . cerr <EOL> pydoc . help . output = self . shell . output_trap . out <EOL> def release_output ( self ) : <EOL> """<STR_LIT>""" <EOL> Term . cout . write = self . __old_cout_write <EOL> Term . cerr . write = self . __old_cerr_write <EOL> sys . stdout = self . __old_stdout <EOL> sys . stderr = self . __old_stderr <EOL> pydoc . help . output = self . __old_help_output <EOL> sys . displayhook = self . __old_display_hook <EOL> def complete ( self , line ) : <EOL> word = self . _get_completion_text ( line ) <EOL> completions = self . ipython0 . complete ( word ) <EOL> key = lambda x : x . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> completions . sort ( key = key ) <EOL> if completions : <EOL> prefix = common_prefix ( completions ) <EOL> line = line [ : - len ( word ) ] + prefix <EOL> return line , completions <EOL> def prefilter_input ( self , input_string ) : <EOL> """<STR_LIT>""" <EOL> input_string = LineFrontEndBase . prefilter_input ( self , input_string ) <EOL> filtered_lines = [ ] <EOL> self . capture_output ( ) <EOL> self . last_result = dict ( number = self . prompt_number ) <EOL> try : <EOL> try : <EOL> for line in input_string . split ( '<STR_LIT:\n>' ) : <EOL> pf = self . ipython0 . prefilter_manager . prefilter_lines <EOL> filtered_lines . append ( pf ( line , False ) . rstrip ( ) ) <EOL> except : <EOL> self . ipython0 . showsyntaxerror ( ) <EOL> self . after_execute ( ) <EOL> finally : <EOL> self . release_output ( ) <EOL> filtered_string = '<STR_LIT:\n>' . join ( filtered_lines ) <EOL> return filtered_string <EOL> def system_call ( self , command_string ) : <EOL> """<STR_LIT>""" <EOL> return os . system ( command_string ) <EOL> def do_exit ( self ) : <EOL> """<STR_LIT>""" <EOL> self . ipython0 . atexit_operations ( ) <EOL> def _get_completion_text ( self , line ) : <EOL> """<STR_LIT>""" <EOL> expression = '<STR_LIT>' <EOL> complete_sep = re . compile ( expression ) <EOL> text = complete_sep . split ( line ) [ - <NUM_LIT:1> ] <EOL> return text </s>
