summaryrefslogtreecommitdiff
path: root/cherrypy/lib/wsgiapp.py
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2006-05-07 06:35:03 +0000
committerRobert Brewer <fumanchu@aminus.org>2006-05-07 06:35:03 +0000
commit8cc98e6c07a312877a2893e7d9cc7d7923d21227 (patch)
tree15cb1a36113cd0245ee189b09a231fd88fb09d44 /cherrypy/lib/wsgiapp.py
parent75d306ecb9f843782254c0250b6afa2df9b4e332 (diff)
downloadcherrypy-git-8cc98e6c07a312877a2893e7d9cc7d7923d21227.tar.gz
Root and config are now isolated per app:
1. object_path is now called path_info, and there's a new request.script_name attribute. This should equal the mount point of the current application. 2. cherrypy.root is gone, use cherrypy.request.app.root for now instead. Perhaps cherrypy.root will reappear and point to that. 3. cherrypy.tree.mount_points has been replaced with cherrypy.tree.apps, a dict of the form {script_name: Application(root, conf)}. 4. The [global] config namespace is now contained in a flat cherrypy.config.globalconf dict. 5. Got rid of handling favicon.ico and the "*" URI (although they may return someday). 6. Upshot is that e.g. test_objectmapping.py takes 1/3 the time as CP 2.2. 7. Moved request body size check into _cprequest from _cpwsgi. 8. Fixed lib/wsgiapp and made a tool for it.
Diffstat (limited to 'cherrypy/lib/wsgiapp.py')
-rw-r--r--cherrypy/lib/wsgiapp.py80
1 files changed, 21 insertions, 59 deletions
diff --git a/cherrypy/lib/wsgiapp.py b/cherrypy/lib/wsgiapp.py
index d96a3cf4..c99562a3 100644
--- a/cherrypy/lib/wsgiapp.py
+++ b/cherrypy/lib/wsgiapp.py
@@ -3,8 +3,6 @@
import sys
import cherrypy
-from cherrypy import _cphttptools
-from cherrypy._cputil import get_object_trail
# is this sufficient for start_response?
@@ -13,43 +11,11 @@ def start_response(status, response_headers, exc_info=None):
headers_dict = dict(response_headers)
cherrypy.response.headers.update(headers_dict)
-def get_path_components(path):
- """returns (script_name, path_info)
-
- determines what part of the path belongs to cp (script_name)
- and what part belongs to the wsgi application (path_info)
- """
- no_parts = ['']
- object_trail = get_object_trail(path)
- root = object_trail.pop(0)
- if not path.endswith('/index'):
- object_trail.pop()
- script_name_parts = [""]
- path_info_parts = [""]
- for (pc,obj) in object_trail:
- if obj:
- script_name_parts.append(pc)
- else:
- path_info_parts.append(pc)
- script_name = "/".join(script_name_parts)
- path_info = "/".join(path_info_parts)
- if len(script_name) > 1 and path.endswith('/'):
- path_info = path_info + '/'
-
- if script_name and not script_name.startswith('/'):
- script_name = '/' + script_name
- if path_info and not path_info.startswith('/'):
- path_info = '/' + path_info
-
- return script_name, path_info
-
def make_environ():
"""grabbed some of below from _cpwsgiserver.py
for hosting WSGI apps in non-WSGI environments (yikes!)
"""
-
- script_name, path_info = get_path_components(cherrypy.request.path)
# create and populate the wsgi environment
environ = dict()
@@ -61,9 +27,9 @@ def make_environ():
environ["wsgi.multiprocess"] = False
environ["wsgi.run_once"] = False
environ["REQUEST_METHOD"] = cherrypy.request.method
- environ["SCRIPT_NAME"] = script_name
- environ["PATH_INFO"] = path_info
- environ["QUERY_STRING"] = cherrypy.request.queryString
+ environ["SCRIPT_NAME"] = cherrypy.request.script_name
+ environ["PATH_INFO"] = cherrypy.request.path_info
+ environ["QUERY_STRING"] = cherrypy.request.query_string
environ["SERVER_PROTOCOL"] = cherrypy.request.version
server_name = getattr(cherrypy.server.httpserver, 'server_name', "None")
environ["SERVER_NAME"] = server_name
@@ -81,26 +47,22 @@ def make_environ():
return environ
-def WSGIAppRequestFactory(wsgi_app, env_update=None):
- """
- wsgi_app - any wsgi application callable
- env_update - a dictionary with arbitrary keys and values to be
- merged with the WSGI environment dictionary.
- """
+def run(app, env=None):
+ """Run the (WSGI) app and set response.body to its output"""
+ try:
+ environ = cherrypy.request.wsgi_environ
+ except AttributeError:
+ environ = make_environ()
+ environ['SCRIPT_NAME'] = cherrypy.request.script_name
+ environ['PATH_INFO'] = cherrypy.request.path_info
+
+ # update the environ with the dict passed to the filter's
+ # constructor
+ if env:
+ environ.update(env)
- class WSGIAppRequest(_cphttptools.Request):
- """A custom Request object for running a WSGI app within CP."""
-
- def process_body(self):
- pass
-
- def main(self, *args, **kwargs):
- """run the wsgi_app and set response.body to its output"""
- try:
- env = self.wsgi_environ
- env['SCRIPT_NAME'], env['PATH_INFO'] = get_path_components(self.path)
- except AttributeError:
- env = make_environ()
- env.update(env_update or {})
- cherrypy.response.body = wsgi_app(env, start_response)
- return WSGIAppRequest
+ # run the wsgi app and have it set response.body
+ cherrypy.response.body = app(environ, start_response)
+
+ return True
+