def create_env(self, code=None, symbols={}): env = ExecutionEnvironment() if code: env.setup(code.get_ast()) # Preload builtins env.loadvars(BUILTINS) # Preload names into environment env.loadvars(symbols) return env
def run_interactive(self, env): print "Pesci 0.1 over Python %s" % sys.version.split(" ")[0] print "Emanuele Faranda <*****@*****.**>" print "Type 'exit' to end interactive mode\n" self._interactive = True partial = "" while self._interactive: try: if partial: prompt = "... " else: prompt = ">>> " cmd = raw_input(prompt) except EOFError: self._interactive = False except KeyboardInterrupt as kint: print kint partial = "" else: # handle continuation lines s = cmd.strip() if s and s[-1] == ":": partial += cmd + "\n" elif partial: if not cmd: # end of command cmd = partial partial = "" else: partial += cmd + "\n" if cmd == "exit": self._interactive = False elif not partial: # evaluate command try: code = PesciCode.from_string(cmd) env.setup(code.get_ast()) self.run(env) except Exception as e: traceback.print_exc(file=sys.stdout)