Home | Trees | Indices | Help |
|
---|
|
1 """A CherryPy tool for hosting a foreign WSGI application.""" 2 3 import sys 4 5 import cherrypy 6 7 8 # is this sufficient for start_response?10 cherrypy.response.status = status 11 headers_dict = dict(response_headers) 12 cherrypy.response.headers.update(headers_dict)1315 """grabbed some of below from wsgiserver.py 16 17 for hosting WSGI apps in non-WSGI environments (yikes!) 18 """ 19 20 request = cherrypy.request 21 22 # create and populate the wsgi environ 23 environ = dict() 24 environ["wsgi.version"] = (1,0) 25 environ["wsgi.url_scheme"] = request.scheme 26 environ["wsgi.input"] = request.rfile 27 environ["wsgi.errors"] = sys.stderr 28 environ["wsgi.multithread"] = True 29 environ["wsgi.multiprocess"] = False 30 environ["wsgi.run_once"] = False 31 environ["REQUEST_METHOD"] = request.method 32 environ["SCRIPT_NAME"] = request.script_name 33 environ["PATH_INFO"] = request.path_info 34 environ["QUERY_STRING"] = request.query_string 35 environ["SERVER_PROTOCOL"] = request.protocol 36 environ["SERVER_NAME"] = request.local.name 37 environ["SERVER_PORT"] = request.local.port 38 environ["REMOTE_HOST"] = request.remote.name 39 environ["REMOTE_ADDR"] = request.remote.ip 40 environ["REMOTE_PORT"] = request.remote.port 41 # then all the http headers 42 headers = request.headers 43 environ["CONTENT_TYPE"] = headers.get("Content-type", "") 44 environ["CONTENT_LENGTH"] = headers.get("Content-length", "") 45 for (k, v) in headers.iteritems(): 46 envname = "HTTP_" + k.upper().replace("-","_") 47 environ[envname] = v 48 return environ49 5052 """Run the given WSGI app and set response.body to its output.""" 53 try: 54 environ = cherrypy.request.wsgi_environ.copy() 55 environ['SCRIPT_NAME'] = cherrypy.request.script_name 56 environ['PATH_INFO'] = cherrypy.request.path_info 57 except AttributeError: 58 environ = make_environ() 59 60 if env: 61 environ.update(env) 62 63 # run the wsgi app and have it set response.body 64 response = app(environ, start_response) 65 try: 66 cherrypy.response.body = [x for x in response] 67 finally: 68 if hasattr(response, "close"): 69 response.close() 70 71 return True72
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Thu Jan 24 16:33:12 2008 | http://epydoc.sourceforge.net |