def wsgiApp(environ, start_response): """The WSGI 'application object' for CherryPy.""" # Trap screen output from BaseHTTPRequestHandler.log_message() if not cherrypy.config.get('server.log_to_screen'): sys.stderr = NullWriter() request = None try: # LOGON_USER is served by IIS, and is the name of the # user after having been mapped to a local account. # Both IIS and Apache set REMOTE_USER, when possible. env = environ.get clientAddr = (env('REMOTE_ADDR', ''), int(env('REMOTE_PORT', -1))) request = cherrypy.server.request(clientAddr, env('REMOTE_ADDR', ''), environ['wsgi.url_scheme']) request.login = (env('LOGON_USER') or env('REMOTE_USER') or None) request.multithread = environ['wsgi.multithread'] request.multiprocess = environ['wsgi.multiprocess'] request.wsgi_environ = environ response = request.run(requestLine(environ), translate_headers(environ), environ['wsgi.input']) s, h, b = response.status, response.header_list, response.body exc = None except (KeyboardInterrupt, SystemExit): raise except: if cherrypy.config.get("server.throw_errors", False): raise tb = _cputil.formatExc() cherrypy.log(tb) if not cherrypy.config.get("server.show_tracebacks", False): tb = "" s, h, b = _cputil.bareError(tb) exc = sys.exc_info() try: start_response(s, h, exc) for chunk in b: # WSGI requires all data to be of type "str". This coercion should # not take any time at all if chunk is already of type "str". # If it's unicode, it could be a big performance hit (x ~500). chunk = str(chunk) yield chunk if request: request.close() request = None except (KeyboardInterrupt, SystemExit), ex: try: if request: request.close() except: cherrypy.log(traceback=True) request = None raise ex
try: if request: request.close() except: cherrypy.log(traceback=True) request = None raise ex except: cherrypy.log(traceback=True) try: if request: request.close() except: cherrypy.log(traceback=True) request = None s, h, b = _cputil.bareError() # CherryPy test suite expects bareError body to be output, # so don't call start_response (which, according to PEP 333, # may raise its own error at that point). for chunk in b: yield str(chunk) # Server components. class CPHTTPRequest(_cpwsgiserver.HTTPRequest): def __init__(self, socket, addr, server): _cpwsgiserver.HTTPRequest.__init__(self, socket, addr, server) mhs = int(cherrypy.config.get('server.max_request_header_size',
def setBareError(self, body=None): self.status, self.header_list, self.body = _cputil.bareError(body)