X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=wrw%2Fdispatch.py;h=768d3f43fdf526cc594935678de1d5c74b34233d;hb=a7a0908019bb95bb2be1c01e97e88f344807ccec;hp=fa1f669d8f43099f6c41c3f919689496409cf725;hpb=7450e2fcc553f66844b34d5c062a965b8fca28c5;p=wrw.git diff --git a/wrw/dispatch.py b/wrw/dispatch.py index fa1f669..768d3f4 100644 --- a/wrw/dispatch.py +++ b/wrw/dispatch.py @@ -1,5 +1,5 @@ import sys, traceback -import env, req, proto +from . import env, req, proto __all__ = ["restart"] @@ -16,34 +16,8 @@ def mangle(result): return result return [str(result)] -class iterproxy(object): - # Makes sure iter(real).next() is called immediately, in order to - # let generator code run. - def __init__(self, real): - self.bk = real - self.bki = iter(real) - self._next = [None] - self.next() - - def __iter__(self): - return self - - def next(self): - if self._next is None: - raise StopIteration() - ret = self._next[0] - try: - self._next[:] = [self.bki.next()] - except StopIteration: - self._next = None - return ret - - def close(self): - if hasattr(self.bk, "close"): - self.bk.close() - def defaulterror(req, excinfo): - import resp + from . import resp traceback.print_exception(*excinfo) raise resp.httperror(500) @@ -60,11 +34,11 @@ def handle(req, startreq, handler): resp = [""] while True: try: - resp = iterproxy(handler(req)) + resp = handler(req) break - except restart, i: + except restart as i: handler = i.handle - except Exception, i: + except Exception as i: if eh is None: raise handler = wraphandler(eh, sys.exc_info())