Added a distutils script.
[wrw.git] / wrw / dispatch.py
1 __all__ = ["restart"]
2
3 class restart(Exception):
4     def handle(self, req):
5         pass
6
7 def mangle(result):
8     try:
9         iter(result)
10     except TypeError:
11         pass
12     else:
13         return result
14     return [str(result)]
15
16 def handle(req, startreq, handler):
17     try:
18         resp = [""]
19         while True:
20             try:
21                 resp = handler(req)
22                 break
23             except restart, i:
24                 handler = i.handle
25         req.commit(startreq)
26         return resp
27     finally:
28         req.cleanup()