def exec_or(path, environ): environ["FilePath"] = path req = Request(environ) base_i = intp.Interpreter() base_i.curr["req"] = req base_i.curr["io"].register("http-stream", req) try: intp.run(open(path).read(), base_i) if "$$main" in base_i.curr: main = base_i.curr["$$main"] passargs = intp.OrObject.from_py([]) main(passargs) except Exception, e: req["Content-type"] = "text/html" return req, "500 Internal Server Error", herror.handle500(e, base_i)
def runsource(self, source): if not oranj.core.lexer.isdone(source): return True try: r = intp.run(source, self.interp) except intp.PyDropI: print "Unfortunately, #!pydrop is not supported in bpython at this time" # TODO: FIXME except intp.DropI: raise EOFError except oranj.core.parser.ParseError: if self.syntaxerror_callback is not None: self.syntaxerror_callback() except Exception, e: if hasattr(self, "write_callback"): print_exception(e, self.interp, self.write_callback) else: def pt(x): print x print_exception(e, self.interp, pt)
def eval(self, source): try: return intp.run(source, self.interp) except: return None