from time import sleep import friendly_traceback.source_cache import stack_data from main import simple_settings from main.exercises import assert_equal from main.text import pages from main.workers.limits import set_limits from main.workers.tracebacks import TracebackSerializer, print_friendly_syntax_error from main.workers.utils import internal_error_result, make_result, output_buffer log = logging.getLogger(__name__) console = InteractiveConsole() console.locals = {"assert_equal": assert_equal} def execute(code_obj): sys.setrecursionlimit(100) try: # noinspection PyTypeChecker exec(code_obj, console.locals) except Exception as e: sys.setrecursionlimit(1000) return TracebackSerializer().format_exception(e) finally: sys.setrecursionlimit(1000) def runner(code_source, code):
def start_backend(data, save): # this will modify the backendlocals to contain the actual backendlocals. # it is used in create(T), to eval() stuff like 'data["kinepolis"]...' global backendlocals console = InteractiveConsole() backendlocals = { "switchDataStructure": switchDataStructure, "data": data, "save": save, "create": create, "example_cinema": example_cinema, } backendlocals.update(classes.__dict__) # add module classes to console backendlocals.update(datastruct.__dict__) # add module datastruct to console backendlocals.update(sorting.__dict__) # add module sorting to console backendlocals.update(origlocals) # reset the stuff that might otherwise be modifed by importing other modules (like __package__ and __name__) console.locals = backendlocals console.locals['credits'] = type(credits)("credits", "\n\n"+fancytext("Anthony")+"\n\n"+fancytext("Pieter")+"\n\n"+fancytext("Stijn")+"\n\n"+fancytext("Evert")) # OMG Tab completion!!! readline.set_completer(rlcompleter.Completer(console.locals).complete) if 'libedit' in readline.__doc__: readline.parse_and_bind("bind ^I rl_complete") # Hi, I'm an Apple computer and I'm special. else: readline.parse_and_bind("tab: complete") # Hi, I'm a Linux computer and things just work for me. # OMG own modification to rlcompleter #readline.set_completer_delims(' \t\n`~!@#$%^&*()-=+[{]}\\|;:\'",<>/?') # original readline.set_completer_delims(' \t\n`~!@#$%^&*()-=+{]}\\|;:,<>/?') # no [,' or " in here! # even more imports console.push("import datetime") while True: # no more color for input, too much bugs c = input("> ") if c == "q": return # exit else: try: if console.push(c): # console.push(c) executes the string c in the console. # if it is True, it means it expects more input (for example a function definition) _input = ' ' totalcommand = '' while _input!='': _input = input('. ') totalcommand += _input+'\n' console.push(totalcommand) except Exception as e: print(rgbtext('Error: %s'%e)) console.resetbuffer() backendlocals = console.locals # again for create(T)
tornado.ioloop.IOLoop.current().spawn_callback(WsHandler.exec_on_all, WsHandler.send_message, json.dumps(dct)) def wait(regex): s = threading.Semaphore(value=0) tornado.ioloop.IOLoop.current().spawn_callback(WsHandler.set_hook, regex, s) s.acquire() assert (request_buffer is not None) return request_buffer console = InteractiveConsole() console.locals = locals() def shell(): # Opens a Python shell # For the record, this code is copied from Gegevensabstractie en structuren :) while True: try: c = input(">>> ") if console.push( c ): # console.push(c) executes the string c in the console. # if it is True, it means it expects more input (for example a function definition) _input = ' ' totalcommand = '' while _input != '':
def shell_thread(**kwargs): hist_loc = ".overwatch_shell.history" console = InteractiveConsole() console.locals = locals() console.locals.update(kwargs) console.locals.update(globals()) console.push("import sys") console.push("import os") console.push("sys.path.append(os.getcwd())") readline.set_completer(rlcompleter.Completer(console.locals).complete) readline.parse_and_bind("tab: complete") if not os.path.isfile(hist_loc): f = open(hist_loc, "x") f.write("\n") f.close() readline.read_history_file(hist_loc) # Opens a Python shell todo = TodoPointer() def snip(location, _todo=todo): _todo.location = location console.locals["snip"] = snip buf = [] def get_input(prompt): if len(buf) > 0: l = buf.pop(0) print("::: " + l.rstrip("\n")) return l else: return input(prompt) while True: try: c = get_input(">>> ") if (not c == ""): if console.push( c ): # console.push(c) executes the string c in the console. # if it is True, it means it expects more input # (for example a function definition) _input = ' ' totalcommand = '' while _input != '': _input = get_input('... ') totalcommand += _input + '\n' console.push(totalcommand) if todo.location is not None: with open(todo.location, 'r') as f: code = f.readlines() buf.extend(code) buf.append("") todo.location = None except (EOFError, KeyboardInterrupt): print("\nShell ended.") break except Exception as e: console.showtraceback() readline.write_history_file(hist_loc)
def send(dct): tornado.ioloop.IOLoop.current().spawn_callback( WsHandler.exec_on_all, WsHandler.send_message, json.dumps(dct)) def wait(regex): s = threading.Semaphore(value=0) tornado.ioloop.IOLoop.current().spawn_callback(WsHandler.set_hook, regex, s) s.acquire() assert(request_buffer is not None) return request_buffer console = InteractiveConsole() console.locals = locals() def shell(): # Opens a Python shell # For the record, this code is copied from Gegevensabstractie en structuren :) while True: try: c = input(">>> ") if console.push(c): # console.push(c) executes the string c in the console. # if it is True, it means it expects more input (for example a function definition) _input = ' ' totalcommand = '' while _input!='': _input = input('... ') totalcommand += _input+'\n' console.push(totalcommand) except (EOFError, KeyboardInterrupt):