"""a WSGI application tool for CherryPy"""importsysimportcherrypy# is this sufficient for start_response?defstart_response(status,response_headers,exc_info=None):cherrypy.response.status=statusheaders_dict=dict(response_headers)cherrypy.response.headers.update(headers_dict)defmake_environ():"""grabbed some of below from _cpwsgiserver.py for hosting WSGI apps in non-WSGI environments (yikes!) """# create and populate the wsgi environmentenviron=dict()environ["wsgi.version"]=(1,0)environ["wsgi.url_scheme"]=cherrypy.request.schemeenviron["wsgi.input"]=cherrypy.request.rfileenviron["wsgi.errors"]=sys.stderrenviron["wsgi.multithread"]=Trueenviron["wsgi.multiprocess"]=Falseenviron["wsgi.run_once"]=Falseenviron["REQUEST_METHOD"]=cherrypy.request.methodenviron["SCRIPT_NAME"]=cherrypy.request.script_nameenviron["PATH_INFO"]=cherrypy.request.path_infoenviron["QUERY_STRING"]=cherrypy.request.query_stringenviron["SERVER_PROTOCOL"]=cherrypy.request.protocolenviron["SERVER_NAME"]=cherrypy.request.local.nameenviron["SERVER_PORT"]=cherrypy.request.local.portenviron["REMOTE_HOST"]=cherrypy.request.remote.nameenviron["REMOTE_ADDR"]=cherrypy.request.remote.ipenviron["REMOTE_PORT"]=cherrypy.request.remote.port# then all the http headersheaders=cherrypy.request.headersenviron["CONTENT_TYPE"]=headers.get("Content-type","")environ["CONTENT_LENGTH"]=headers.get("Content-length","")for(k,v)inheaders.iteritems():envname="HTTP_"+k.upper().replace("-","_")environ[envname]=vreturnenvirondefrun(app,env=None):"""Run the (WSGI) app and set response.body to its output"""try:environ=cherrypy.request.wsgi_environenviron['SCRIPT_NAME']=cherrypy.request.script_nameenviron['PATH_INFO']=cherrypy.request.path_infoexceptAttributeError:environ=make_environ()ifenv:environ.update(env)# run the wsgi app and have it set response.bodycherrypy.response.body=app(environ,start_response)returnTrue