Changeset 1608
- Timestamp:
- 02/01/07 13:06:34
- Files:
-
- trunk/cherrypy/__init__.py (modified) (3 diffs)
- trunk/cherrypy/_cpengine.py (modified) (2 diffs)
- trunk/cherrypy/_cpmodpy.py (modified) (2 diffs)
- trunk/cherrypy/_cpserver.py (modified) (1 diff)
- trunk/cherrypy/_cptools.py (modified) (1 diff)
- trunk/cherrypy/_cpwsgi.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/__init__.py
r1602 r1608 1 """Global module that all modules developing with CherryPy should import.""" 1 """CherryPy is a pythonic, object-oriented HTTP framework. 2 3 4 CherryPy consists of not one, but four separate API layers. 5 6 The APPLICATION LAYER is the simplest. CherryPy applications are written as 7 a tree of classes and methods, where each branch in the tree corresponds to 8 a branch in the URL path. Each method is a 'page handler', which receives 9 GET and POST params as keyword arguments, and returns or yields the (HTML) 10 body of the response. The special method name 'index' is used for paths 11 that end in a slash, and the special method name 'default' is used to 12 handle multiple paths via a single handler. This layer also includes: 13 14 * the 'exposed' attribute (and cherrypy.expose) 15 * cherrypy.quickstart() 16 * _cp_config attributes 17 * cherrypy.tools (including cherrypy.session) 18 * cherrypy.url() 19 20 The ENVIRONMENT LAYER is used by developers at all levels. It provides 21 information about the current request and response, plus the application 22 and server environment, via a (default) set of top-level objects: 23 24 * cherrypy.request 25 * cherrypy.response 26 * cherrypy.engine 27 * cherrypy.server 28 * cherrypy.tree 29 * cherrypy.config 30 * cherrypy.thread_data 31 * cherrypy.log 32 * cherrypy.HTTPError, NotFound, and HTTPRedirect 33 * cherrypy.lib 34 35 The EXTENSION LAYER allows advanced users to construct and share their own 36 plugins. It consists of: 37 38 * Hook API 39 * Tool API 40 * Toolbox API 41 * Dispatch API 42 * Config Namespace API 43 44 Finally, there is the CORE LAYER, which uses the core API's to construct 45 the default components which are available at higher layers. You can think 46 of the default components as the 'reference implementation' for CherryPy. 47 Megaframeworks (and advanced users) may replace the default components 48 with customized or extended components. The core API's are: 49 50 * Application API 51 * Engine API 52 * Request API 53 * Server API 54 * WSGI API 55 56 These API's are described in the CherryPy specification: 57 http://www.cherrypy.org/wiki/CherryPySpec 58 """ 2 59 3 60 __version__ = "3.0.1alpha" … … 133 190 # a new HTTP conversation, yet still refer to them as module-level globals 134 191 # in a thread-safe way. 135 _serving = _local() 192 class _Serving(_local): 193 """An interface for registering request and response objects.""" 194 195 def load(self, request, response): 196 self.request = request 197 self.response = response 198 199 def clear(self): 200 """Remove all attributes of self.""" 201 self.__dict__.clear() 202 203 serving = _serving = _Serving() 136 204 137 205 … … 327 395 # if you're using vhosts or tools.proxy. 328 396 if base is None: 329 f = server.socket_file 330 if f: 331 base = f 332 else: 333 host = server.socket_host 334 if not host: 335 # The empty string signifies INADDR_ANY. 336 # Look up the host name, which should be 337 # the safest thing to spit out in a URL. 338 import socket 339 host = socket.gethostname() 340 port = server.socket_port 341 if server.ssl_certificate: 342 scheme = "https" 343 if port != 443: 344 host += ":%s" % port 345 else: 346 scheme = "http" 347 if port != 80: 348 host += ":%s" % port 349 base = "%s://%s" % (scheme, host) 397 base = server.base() 398 350 399 path = (script_name or "") + path 351 400 newurl = base + path + qs trunk/cherrypy/_cpengine.py
r1590 r1608 206 206 def wait(self): 207 207 """Block the caller until ready to receive requests (or error).""" 208 while not self.ready:208 while not (self.state == STARTED): 209 209 time.sleep(.1) 210 211 def _is_ready(self):212 return bool(self.state == STARTED)213 ready = property(_is_ready, doc="Return True if the engine is ready to"214 " receive requests, False otherwise.")215 210 216 211 def request(self, local_host, remote_host, scheme="http", 217 212 server_protocol="HTTP/1.1"): 218 """Obtain an HTTP Request object.213 """Obtain and return an HTTP Request object. (Core) 219 214 220 215 local_host should be an http.Host object with the server info. … … 237 232 req = self.request_class(local_host, remote_host, scheme, 238 233 server_protocol) 239 cherrypy._serving.request = req240 cherrypy. _serving.response = resp = self.response_class()234 resp = self.response_class() 235 cherrypy.serving.load(req, resp) 241 236 self.servings.append((req, resp)) 242 237 return req 243 238 239 def release(self): 240 """Close and de-reference the current request and response. (Core)""" 241 req = cherrypy.serving.request 242 243 try: 244 req.close() 245 except: 246 cherrypy.log(traceback=True) 247 248 try: 249 self.servings.remove((req, cherrypy.serving.response)) 250 except ValueError: 251 pass 252 253 cherrypy.serving.clear() 254 244 255 def monitor(self): 245 """Check timeout on all responses. """256 """Check timeout on all responses. (Internal)""" 246 257 if self.state == STARTED: 247 258 for req, resp in self.servings: trunk/cherrypy/_cpmodpy.py
r1433 r1608 179 179 break 180 180 except cherrypy.InternalRedirect, ir: 181 request.close()181 cherrypy.engine.release() 182 182 prev = request 183 183 … … 199 199 200 200 send_response(req, response.status, response.header_list, response.body) 201 request.close()201 cherrypy.engine.release() 202 202 except: 203 203 tb = format_exc() trunk/cherrypy/_cpserver.py
r1528 r1608 175 175 self.stop() 176 176 self.start() 177 178 def base(self): 179 """Return the base (scheme://host) for this server manager.""" 180 if self.socket_file: 181 return self.socket_file 182 183 host = self.socket_host 184 if not host: 185 # The empty string signifies INADDR_ANY. Look up the host name, 186 # which should be the safest thing to spit out in a URL. 187 host = socket.gethostname() 188 189 port = self.socket_port 190 191 if self.ssl_certificate: 192 scheme = "https" 193 if port != 443: 194 host += ":%s" % port 195 else: 196 scheme = "http" 197 if port != 80: 198 host += ":%s" % port 199 200 return "%s://%s" % (scheme, host) 177 201 178 202 trunk/cherrypy/_cptools.py
r1580 r1608 16 16 17 17 CherryPy config: 18 Hookpoints are places in the CherryPy request-handling process 19 which may hand off control to registered callbacks. The Request 20 object possesses a "hooks" attribute (a HookMap) for manipulating 21 this. If a tool exposes a "_setup" callable, it will be called 18 If a tool exposes a "_setup" callable, it will be called 22 19 once per Request (if the feature is "turned on" via config). 23 20 trunk/cherrypy/_cpwsgi.py
r1531 r1608 193 193 194 194 def close(self): 195 if hasattr(self.request, "close"): 196 try: 197 self.request.close() 198 except: 199 _cherrypy.log(traceback=True) 195 _cherrypy.engine.release() 200 196 201 197 def get_engine_request(self, environ, cpapp):

