Changeset 1260
- Timestamp:
- 08/21/06 03:10:15
- Files:
-
- trunk/cherrypy/_cpmodpy.py (modified) (1 diff)
- trunk/cherrypy/_cprequest.py (modified) (1 diff)
- trunk/cherrypy/_cptree.py (modified) (3 diffs)
- trunk/cherrypy/_cpwsgi.py (modified) (3 diffs)
- trunk/cherrypy/test/test_wsgiapps.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cpmodpy.py
r1251 r1260 91 91 request.multiprocess = bool(forked) 92 92 93 # Run the CherryPy Request object and obtain the response 94 headers = req.headers_in.items() 95 rfile = _ReadOnlyRequest(req) 96 response = request.run(req.method, req.uri, req.args or "", 97 req.protocol, headers, rfile) 98 99 send_response(req, response.status, response.header_list, response.body) 100 request.close() 93 sn = cherrypy.tree.script_name(req.uri or "/") 94 if sn is None: 95 send_response(req, '404 Not Found', [], '') 96 else: 97 request.app = cherrypy.tree.apps[sn] 98 99 # Run the CherryPy Request object and obtain the response 100 headers = req.headers_in.items() 101 rfile = _ReadOnlyRequest(req) 102 response = request.run(req.method, req.uri, req.args or "", 103 req.protocol, headers, rfile) 104 105 send_response(req, response.status, response.header_list, response.body) 106 request.close() 101 107 except: 102 108 tb = format_exc() trunk/cherrypy/_cprequest.py
r1254 r1260 161 161 self.process_headers() 162 162 163 if self.app is None:164 # Some interfaces (like WSGI) may have already set self.app.165 # If not, look up the app for this path.166 self.script_name = sn = cherrypy.tree.script_name(self.path)167 if sn is None:168 # No app was found to handle this path. Rather than169 # abort here, we leave self.app == None so NotFound170 # can be raised later (with proper error handling171 # and response finalization). See self.respond.172 self.script_name = ""173 else:174 self.app = cherrypy.tree.apps[sn]175 else:176 self.script_name = self.app.script_name177 178 163 # path_info should be the path from the 179 164 # app root (script_name) to the handler. 165 self.script_name = self.app.script_name 180 166 self.path_info = self.path[len(self.script_name.rstrip("/")):] 181 167 trunk/cherrypy/_cptree.py
r1250 r1260 1 1 import logging 2 2 3 import cherrypy4 3 from cherrypy import config, _cpwsgi 5 4 6 5 7 class Application :6 class Application(object): 8 7 """A CherryPy Application. 9 8 … … 38 37 if self._script_name is None: 39 38 # None signals that the script name should be pulled from WSGI environ. 39 import cherrypy 40 40 return cherrypy.request.wsgi_environ['SCRIPT_NAME'] 41 41 return self._script_name 42 42 def _set_script_name(self, value): 43 43 self._script_name = value 44 script_name = property( _get_script_name,_set_script_name)44 script_name = property(fget=_get_script_name, fset=_set_script_name) 45 45 46 46 def merge(self, conf): … … 149 149 150 150 def __call__(self, environ, start_response): 151 return _cpwsgi._wsgi_callable(environ, start_response) 151 # If you're calling this, then you're probably setting SCRIPT_NAME 152 # to '' (some WSGI servers always set SCRIPT_NAME to ''). 153 # Try to look up the app using the full path. 154 path = environ.get('SCRIPT_NAME', '') + environ.get('PATH_INFO', '') 155 sn = self.script_name(path or "/") 156 if sn is None: 157 start_response('404 Not Found', []) 158 return [] 159 160 app = self.apps[sn] 161 162 # Correct the SCRIPT_NAME and PATH_INFO environ entries. 163 environ = environ.copy() 164 environ['SCRIPT_NAME'] = sn 165 environ['PATH_INFO'] = path[len(sn.rstrip("/")):] 166 return app(environ, start_response) 152 167 trunk/cherrypy/_cpwsgi.py
r1259 r1260 27 27 28 28 29 def _wsgi_callable(environ, start_response, app =None):29 def _wsgi_callable(environ, start_response, app): 30 30 request = None 31 31 try: … … 47 47 request.wsgi_environ = environ 48 48 49 if app: 50 request.app = app 49 request.app = app 51 50 52 51 path = env('SCRIPT_NAME', '') + env('PATH_INFO', '') … … 175 174 176 175 s = _cpwsgiserver.CherryPyWSGIServer 177 s.__init__(self, bind_addr, cherrypy.tree, 176 # We could just pass cherrypy.tree, but by passing tree.apps, 177 # we get correct SCRIPT_NAMEs as early as possible. 178 s.__init__(self, bind_addr, cherrypy.tree.apps.items(), 178 179 conf('server.thread_pool'), 179 180 conf('server.socket_host'), trunk/cherrypy/test/test_wsgiapps.py
r1256 r1260 19 19 for k in keys: 20 20 yield '%s: %s\n' % (k,environ[k]) 21 21 22 22 def reversing_middleware(app): 23 23 def _app(environ, start_response): … … 54 54 cherrypy.tree.graft(test_app, '/hosted/app1') 55 55 56 app = cherrypy.Application(Root(), None) 56 # Set script_name explicitly to None to signal CP that it should 57 # be pulled from the WSGI environ each time. 58 app = cherrypy.Application(Root(), script_name=None) 57 59 cherrypy.tree.graft(reversing_middleware(app), '/hosted/app2') 58 60

