Changeset 1249
- Timestamp:
- 08/17/06 18:29:23
- Files:
-
- trunk/cherrypy/__init__.py (modified) (1 diff)
- trunk/cherrypy/_cptree.py (modified) (5 diffs)
- trunk/cherrypy/_cpwsgi.py (modified) (2 diffs)
- trunk/cherrypy/test/benchmark.py (modified) (1 diff)
- trunk/cherrypy/test/helper.py (modified) (2 diffs)
- trunk/cherrypy/test/modpy.py (modified) (1 diff)
- trunk/cherrypy/test/test_response_headers.py (modified) (previous)
- trunk/cherrypy/test/test_tutorials.py (modified) (1 diff)
- trunk/cherrypy/test/test_wsgiapps.py (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/__init__.py
r1243 r1249 14 14 import _cptree 15 15 tree = _cptree.Tree() 16 from _cptree import Application 16 17 import _cpengine 17 18 engine = _cpengine.Engine() trunk/cherrypy/_cptree.py
r1156 r1249 2 2 import sys 3 3 4 from cherrypy import config 4 import cherrypy 5 from cherrypy import config, _cpwsgi 5 6 6 7 7 8 class Application: 8 """A CherryPy Application.""" 9 """A CherryPy Application. 10 11 An instance of this class may also be used as a WSGI callable 12 (WSGI application object) for itself. 13 14 root: the top-most container of page handlers for this app. 15 script_name: the URL "mount point" for this app; for example, 16 if script_name is "/my/cool/app", then the URL 17 "http://my.domain.tld/my/cool/app/page1" might be handled 18 by a "page1" method on the root object. If script_name is 19 explicitly set to None, then CherryPy will attempt to provide 20 it each time from request.wsgi_environ['SCRIPT_NAME']. 21 conf: a dict of {path: pathconf} pairs, where 'pathconf' is itself 22 a dict of {key: value} pairs. 23 """ 9 24 10 25 def __init__(self, root, script_name="", conf=None): … … 20 35 if conf: 21 36 self.merge(conf) 37 38 def _get_script_name(self): 39 if self._script_name is None: 40 # None signals that the script name should be pulled from WSGI environ. 41 return cherrypy.request.wsgi_environ['SCRIPT_NAME'] 42 return self._script_name 43 def _set_script_name(self, value): 44 self._script_name = value 45 script_name = property(_get_script_name, _set_script_name) 22 46 23 47 def merge(self, conf): … … 48 72 host += ":%s" % port 49 73 return scheme + host + self.script_name 74 75 def __call__(self, environ, start_response): 76 return _cpwsgi._wsgi_callable(environ, start_response, app=self) 50 77 51 78 52 79 class Tree: 53 """A registry of CherryPy applications, mounted at diverse points.""" 80 """A registry of CherryPy applications, mounted at diverse points. 81 82 An instance of this class may also be used as a WSGI callable 83 (WSGI application object), in which case it dispatches to all 84 mounted apps. 85 """ 54 86 55 87 def __init__(self): … … 72 104 73 105 return app 106 107 def graft(self, wsgi_callable, script_name=""): 108 """Mount a wsgi callable at the given script_name.""" 109 # Next line both 1) strips trailing slash and 2) maps "/" -> "". 110 script_name = script_name.rstrip("/") 111 self.apps[script_name] = wsgi_callable 74 112 75 113 def script_name(self, path=None): … … 110 148 from cherrypy.lib import http 111 149 return http.urljoin(script_name, path) 150 151 def __call__(self, environ, start_response): 152 return _cpwsgi._wsgi_callable(environ, start_response) 112 153 trunk/cherrypy/_cpwsgi.py
r1230 r1249 113 113 yield chunk 114 114 115 def wsgiApp(environ, start_response):116 """The WSGI 'application object' for CherryPy.117 118 Use this as the same WSGI callable for all your CP apps.119 """120 return _wsgi_callable(environ, start_response)121 122 def make_app(app):123 """Factory for making separate WSGI 'application objects' for each CP app.124 125 Example:126 # 'app' will be a CherryPy application object127 app = cherrypy.tree.mount(Root(), "/", localconf)128 129 # 'wsgi_app' will be a WSGI application130 wsgi_app = _cpwsgi.make_app(app)131 """132 def single_app(environ, start_response):133 return _wsgi_callable(environ, start_response, app)134 return single_app135 136 137 115 138 116 # Server components # … … 197 175 conf('server.socket_port')) 198 176 199 apps = [(base, wsgiApp) for base in cherrypy.tree.apps]200 201 177 s = _cpwsgiserver.CherryPyWSGIServer 202 s.__init__(self, bind_addr, apps,178 s.__init__(self, bind_addr, cherrypy.tree, 203 179 conf('server.thread_pool'), 204 180 conf('server.socket_host'), trunk/cherrypy/test/benchmark.py
r1225 r1249 296 296 PythonFixupHandler cherrypy.test.benchmark::startup_modpython 297 297 PythonHandler modpython_gateway::handler 298 PythonOption wsgi.application cherrypy ._cpwsgi::wsgiApp298 PythonOption wsgi.application cherrypy::tree 299 299 PythonDebug On 300 300 %s%s trunk/cherrypy/test/helper.py
r1219 r1249 102 102 args=(moduleNames, conf)) 103 103 104 def sync_apps(profile=False): 105 apps = [] 106 for base, app in cherrypy.tree.apps.iteritems(): 107 if base == "/": 108 base = "" 109 if profile: 110 apps.append((base, profiler.make_app(app, aggregate=False))) 111 else: 112 apps.append((base, app)) 113 apps.sort() 114 apps.reverse() 115 for s in cherrypy.server.httpservers: 116 s.mount_points = apps 117 104 118 def _run_test_suite_thread(moduleNames, conf): 105 from cherrypy import _cpwsgi106 119 for testmod in moduleNames: 107 120 # Must run each module in a separate suite, … … 118 131 # The setup functions probably mounted new apps. 119 132 # Tell our server about them. 120 apps = [] 121 for base, app in cherrypy.tree.apps.iteritems(): 122 if base == "/": 123 base = "" 124 if conf.get("profiling.on", False): 125 apps.append((base, profiler.make_app(_cpwsgi.wsgiApp))) 126 ## apps.append((base, profiler.make_app(_cpwsgi.wsgiApp, aggregate=True))) 127 else: 128 apps.append((base, _cpwsgi.wsgiApp)) 129 ## # We could use the following line, but it breaks test_tutorials 130 ## apps.append((base, _cpwsgi.make_app(app))) 131 apps.sort() 132 apps.reverse() 133 for s in cherrypy.server.httpservers: 134 s.mount_points = apps 133 sync_apps(profile=conf.get("profiling.on", False)) 135 134 136 135 suite = CPTestLoader.loadTestsFromName(testmod) trunk/cherrypy/test/modpy.py
r1150 r1249 62 62 PythonOption testmod %s 63 63 PythonHandler modpython_gateway::handler 64 PythonOption wsgi.application cherrypy ._cpwsgi::wsgiApp64 PythonOption wsgi.application cherrypy::tree 65 65 PythonDebug On 66 66 """ trunk/cherrypy/test/test_tutorials.py
r1209 r1249 28 28 app.root.sessions = sessions 29 29 app.root.traceback_setting = traceback_setting 30 31 helper.sync_apps() 30 32 load_tut_module.exposed = True 31 33

