def run_multiline_interactive_console(mainmodule=None): import code if mainmodule is None: import __main__ as mainmodule console = code.InteractiveConsole(mainmodule.__dict__) def more_lines(unicodetext): # ooh, look at the hack: src = "#coding:utf-8\n" + unicodetext.encode('utf-8') try: code = console.compile(src, '<input>', 'single') except (OverflowError, SyntaxError, ValueError): return False else: return code is None while 1: try: ps1 = getattr(sys, 'ps1', '>>> ') ps2 = getattr(sys, 'ps2', '... ') try: statement = multiline_input(more_lines, ps1, ps2) except EOFError: break more = console.push(statement) assert not more except KeyboardInterrupt: console.write("\nKeyboardInterrupt\n") console.resetbuffer()
def run_multiline_interactive_console(mainmodule=None, future_flags=0): import code if mainmodule is None: import __main__ as mainmodule console = code.InteractiveConsole(mainmodule.__dict__, filename='<stdin>') if future_flags: console.compile.compiler.flags |= future_flags def more_lines(unicodetext): # ooh, look at the hack: src = "#coding:utf-8\n"+_strip_final_indent(unicodetext).encode('utf-8') try: code = console.compile(src, '<stdin>', 'single') except (OverflowError, SyntaxError, ValueError): return False else: return code is None while 1: try: ps1 = getattr(sys, 'ps1', '>>> ') ps2 = getattr(sys, 'ps2', '... ') try: statement = multiline_input(more_lines, ps1, ps2, returns_unicode=True) except EOFError: break more = console.push(_strip_final_indent(statement)) assert not more except KeyboardInterrupt: console.write("\nKeyboardInterrupt\n") console.resetbuffer() except MemoryError: console.write("\nMemoryError\n") console.resetbuffer()
def run_multiline_interactive_console(mainmodule=None): import code if mainmodule is None: import __main__ as mainmodule console = code.InteractiveConsole(mainmodule.__dict__) def more_lines(unicodetext): # ooh, look at the hack: src = "#coding:utf-8\n"+unicodetext.encode('utf-8') try: code = console.compile(src, '<input>', 'single') except (OverflowError, SyntaxError, ValueError): return False else: return code is None while 1: try: ps1 = getattr(sys, 'ps1', '>>> ') ps2 = getattr(sys, 'ps2', '... ') try: statement = multiline_input(more_lines, ps1, ps2) except EOFError: break more = console.push(statement) assert not more except KeyboardInterrupt: console.write("\nKeyboardInterrupt\n") console.resetbuffer()
def run_multiline_interactive_console(mainmodule=None): import code import __main__ mainmodule = mainmodule or __main__ console = code.InteractiveConsole(mainmodule.__dict__) def more_lines(unicodetext): # ooh, look at the hack: src = "#coding:utf-8\n" + unicodetext.encode("utf-8") try: code = console.compile(src, "<input>", "single") except (OverflowError, SyntaxError, ValueError): return False else: return code is None while 1: try: ps1 = getattr(sys, "ps1", ">>> ") ps2 = getattr(sys, "ps2", "... ") try: statement = multiline_input(more_lines, ps1, ps2, returns_unicode=True) except EOFError: break more = console.push(statement) assert not more except KeyboardInterrupt: console.write("\nKeyboardInterrupt\n") console.resetbuffer()
def run_multiline_interactive_console(mainmodule=None, future_flags=0): import code import __main__ mainmodule = mainmodule or __main__ console = code.InteractiveConsole(mainmodule.__dict__, filename='<stdin>') if future_flags: console.compile.compiler.flags |= future_flags def more_lines(unicodetext): # ooh, look at the hack: if sys.version_info < (3,): src = "#coding:utf-8\n"+_strip_final_indent(unicodetext).encode('utf-8') else: src = _strip_final_indent(unicodetext) try: code = console.compile(src, '<stdin>', 'single') except (OverflowError, SyntaxError, ValueError): return False else: return code is None while 1: try: try: sys.stdout.flush() except: pass ps1 = getattr(sys, 'ps1', '>>> ') ps2 = getattr(sys, 'ps2', '... ') try: statement = multiline_input(more_lines, ps1, ps2, returns_unicode=True) except EOFError: break more = console.push(_strip_final_indent(statement)) assert not more except KeyboardInterrupt: console.write("\nKeyboardInterrupt\n") console.resetbuffer() except MemoryError: console.write("\nMemoryError\n") console.resetbuffer()
def run_multiline_interactive_console(mainmodule=None): import code import __main__ mainmodule = mainmodule or __main__ console = code.InteractiveConsole(mainmodule.__dict__, filename='<stdin>') def more_lines(unicodetext): # ooh, look at the hack: if sys.version_info < (3,): src = "#coding:utf-8\n"+unicodetext.encode('utf-8') else: src = unicodetext try: code = console.compile(src, '<stdin>', 'single') except (OverflowError, SyntaxError, ValueError): return False else: return code is None while 1: try: ps1 = getattr(sys, 'ps1', '>>> ') ps2 = getattr(sys, 'ps2', '... ') try: statement = multiline_input(more_lines, ps1, ps2, returns_unicode=True) except EOFError: break more = console.push(statement) assert not more except KeyboardInterrupt: console.write("\nKeyboardInterrupt\n") console.resetbuffer() except MemoryError: console.write("\nMemoryError\n") console.resetbuffer()