Dolda2000 GitWeb
/
wrw.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Converted URL quoting to Python3.
[wrw.git]
/
wrw
/
dispatch.py
diff --git
a/wrw/dispatch.py
b/wrw/dispatch.py
index
5a7bda0
..
5276892
100644
(file)
--- a/
wrw/dispatch.py
+++ b/
wrw/dispatch.py
@@
-1,3
+1,6
@@
+import sys, traceback
+from . import env, req, proto
+
__all__ = ["restart"]
class restart(Exception):
__all__ = ["restart"]
class restart(Exception):
@@
-13,16
+16,41
@@
def mangle(result):
return result
return [str(result)]
return result
return [str(result)]
+def defaulterror(req, excinfo):
+ from . import resp
+ traceback.print_exception(*excinfo)
+ raise resp.httperror(500)
+
+def wraphandler(handler, excinfo):
+ def wrapped(req):
+ return handler(req, excinfo)
+ wrapped.__wrapped__ = handler
+ return wrapped
+
+errorhandler = env.var(defaulterror)
+
def handle(req, startreq, handler):
def handle(req, startreq, handler):
+ eh = errorhandler.val
try:
resp = [""]
while True:
try:
resp = handler(req)
break
try:
resp = [""]
while True:
try:
resp = handler(req)
break
- except restart
,
i:
+ except restart
as
i:
handler = i.handle
handler = i.handle
+ except Exception as i:
+ if eh is None:
+ raise
+ handler = wraphandler(eh, sys.exc_info())
+ eh = None
req.commit(startreq)
return resp
finally:
req.cleanup()
req.commit(startreq)
return resp
finally:
req.cleanup()
+
+def handleenv(env, startreq, handler):
+ if not "HTTP_HOST" in env:
+ return proto.simpleerror(env, startreq, 400, "Bad Request", "Request must include Host header.")
+ r = req.origrequest(env)
+ return handle(r, startreq, handler)