2 from . import env, req, proto
6 class restart(Exception):
19 def defaulterror(req, excinfo):
21 traceback.print_exception(*excinfo)
23 raise resp.httperror(500)
25 def wraphandler(handler, excinfo):
27 return handler(req, excinfo)
28 wrapped.__wrapped__ = handler
31 errorhandler = env.var(defaulterror)
33 def handle(req, startreq, handler):
43 except Exception as i:
46 handler = wraphandler(eh, sys.exc_info())
53 def handleenv(env, startreq, handler):
54 if not "HTTP_HOST" in env:
55 return proto.simpleerror(env, startreq, 400, "Bad Request", "Request must include Host header.")
56 r = req.origrequest(env)
57 return handle(r, startreq, handler)
59 def exterror(env, startreq):
63 if "Response-Code" in req.ihead:
65 code = int(req.ihead["Response-Code"])
68 raise resp.httperror(code)
69 return handleenv(env, startreq, handler)