示例#1
0
    def __init__(self, environ, start_response):
        cny_log.setupLogging(consoleLevel=logging.INFO, consoleFormat='apache',
                consoleStream=environ['wsgi.errors'])
        # gunicorn likes to umask(0) when daemonizing, so put back something
        # reasonable if that's the case.
        oldUmask = os.umask(022)
        if oldUmask != 0:
            os.umask(oldUmask)

        self.start_response = start_response
        try:
            self.req = self.requestFactory(environ)
        except:
            log.exception("Error parsing request:")
            response = web_exc.HTTPBadRequest()
            self.iterable = response(environ, start_response)
            return

        if self.cfg is None:
            type(self).cfg = config.UpsrvConfig.load()
        self.req.cfg = self.cfg

        try:
            response = self.handleRequest()
        except web_exc.HTTPException, exc:
            response = exc
示例#2
0
        if self.cfg is None:
            type(self).cfg = config.UpsrvConfig.load()
        self.req.cfg = self.cfg

        try:
            response = self.handleRequest()
        except web_exc.HTTPException, exc:
            response = exc
        except:
            exc_info = sys.exc_info()
            response = self.handleError(exc_info)
        finally:
            logging.shutdown()
        if callable(response):
            self.iterable = response(environ, start_response)
        else:
            self.iterable = response

    def __iter__(self):
        return iter(self.iterable)

    def handleError(self, exc_info):
        # FIXME: mail tracebacks
        log.exception("Unhandled exception:")
        return web_exc.HTTPInternalServerError(explanation=
                "Something has gone terribly wrong. "
                "Check the webserver logs for details.")

    def handleRequest(self):
        if 'x-conary-servername' in self.req.headers: