Ejemplo n.º 1
0
 def __call__(self, env, callback):
     """ Called to execute the request """
     uri = env['PATH_INFO']
     try:
         handler, args = self.find_route(uri)
         h = handler(self, env)
         ret = h.execute(*args)
         status = util.code_to_status(h.status)
         callback(status, h.headers)
         return iter(ret)
     ## if a request is made via a method we have not implemented
     ## a request handler for, an AttributeError with be raised
     ## a 405 Method Not ALlowed status might work here, but for
     ## now we will just send a 404 status
     except AttributeError:
         traceback.print_exc(file=env['wsgi.errors'])
         handler = ErrorRequestHandler(self, env, status=404)
         status = util.code_to_status(handler.status)
         callback(status, handler.headers)
         return iter(handler.execute())
     ## if an HTTPError was thrown, send down an error page
     ## based on the thrown HTTP status code
     except HTTPError, e:
         traceback.print_exc(file=env['wsgi.errors'])
         handler = ErrorRequestHandler(self, env, status=e.status)
         status = util.code_to_status(handler.status)
         callback(status, handler.headers)
         return iter(handler.execute())
Ejemplo n.º 2
0
 def execute(self):
     return util.code_to_status(self.status)
Ejemplo n.º 3
0
            return iter(handler.execute())
        ## if an HTTPError was thrown, send down an error page
        ## based on the thrown HTTP status code
        except HTTPError, e:
            traceback.print_exc(file=env['wsgi.errors'])
            handler = ErrorRequestHandler(self, env, status=e.status)
            status = util.code_to_status(handler.status)
            callback(status, handler.headers)
            return iter(handler.execute())
        ## return a 500 Internal Server Error page if any
        ## other exceptions have been thrown. We will also send
        ## a traceback for further investigation of the error
        except:
            traceback.print_exc(file=env['wsgi.errors'])
            handler = ErrorRequestHandler(self, env, status=500)
            status = util.code_to_status(handler.status)
            callback(status, handler.headers)
            return iter(handler.execute())

class ErrorRequestHandler(RequestHandler):
    """ Generate error pages based on HTTP status codes

    When supplied with an HTTP status code (most likely from a thrown
    HTTPError), generate an error page with a short status message,
    taken from httplib.responses for the specified status code

    Attributes:
        application -- Instance of WebApplication from which we were called
        env         -- WSGI environment dict
        status      -- HTTP status code
    """