def __call__(self, environ, start_response): # TODO: The error handler must be put here ## return self.run(environ, start_response) if "biz.request" in environ: req = environ["biz.request"] else: req = Request(environ, start_response) try: resp = self.run(req) except AbortSignal, e: resp = Response(e.message) resp.status = e.status
else: req = Request(environ, start_response) try: resp = self.run(req) except AbortSignal, e: resp = Response(e.message) resp.status = e.status except RedirectionSignal, e: resp = Response("", location=e.location) resp.status = e.status if not isinstance(resp, Response): if resp is None: resp = "" resp = Response(resp) if (not "content-length" in resp.headers) and \ (isinstance(resp.content, str)): resp.headers["content-length"] = str(len(resp.content)) resp._resolve() content = resp.content if not req.start_response_called: req.start_response(resp.status, resp.headers, req.exc_info) if isinstance(content, str): return [content] elif isiterable(content): return content