Changeset 1288
- Timestamp:
- 08/28/06 13:39:08
- Files:
-
- trunk/cherrypy/LICENSE.txt (modified) (1 diff)
- trunk/cherrypy/__init__.py (modified) (1 diff)
- trunk/cherrypy/_cpconfig.py (modified) (1 diff)
- trunk/cherrypy/_cprequest.py (modified) (2 diffs)
- trunk/cherrypy/lib/caching.py (modified) (4 diffs)
- trunk/cherrypy/lib/cptools.py (modified) (4 diffs)
- trunk/cherrypy/lib/wsgiapp.py (modified) (1 diff)
- trunk/cherrypy/test/test_config.py (modified) (1 diff)
- trunk/cherrypy/test/test_conn.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/LICENSE.txt
r768 r1288 1 Copyright (c) 2004-200 5, CherryPy Team (team@cherrypy.org)1 Copyright (c) 2004-2006, CherryPy Team (team@cherrypy.org) 2 2 All rights reserved. 3 3 trunk/cherrypy/__init__.py
r1285 r1288 139 139 return expose_(func) 140 140 else: 141 # expose is being called as a decorator142 141 if alias is None: 143 alias = func 144 return expose_ 142 # expose is being called as a decorator "@expose" 143 func.exposed = True 144 return func 145 else: 146 # expose is returning a decorator "@expose(alias=...)" 147 return expose_ 145 148 146 149 trunk/cherrypy/_cpconfig.py
r1285 r1288 170 170 elif namespace == "log": 171 171 setattr(cherrypy.log, atoms[1], v) 172 173 def wrap(**kwargs):174 """Decorator to set _cp_config on a handler using the given kwargs."""175 def wrapper(f):176 if not hasattr(f, "_cp_config"):177 f._cp_config = {}178 f._cp_config.update(kwargs)179 return f180 return wrapper181 wrap = staticmethod(wrap)182 172 183 173 trunk/cherrypy/_cprequest.py
r1285 r1288 240 240 resource, vpath = self.find_handler(path_info) 241 241 242 # Decode any leftover %2F in the virtual_path atoms.243 vpath = [x.replace("%2F", "/") for x in vpath]244 245 242 if resource: 246 243 # Set Allow header … … 252 249 253 250 # Find the subhandler 254 meth = cherrypy.request.method.upper()251 meth = request.method.upper() 255 252 func = getattr(resource, meth, None) 256 253 if func is None and meth == "HEAD": 257 254 func = getattr(resource, "GET", None) 258 255 if func: 256 # Decode any leftover %2F in the virtual_path atoms. 257 vpath = [x.replace("%2F", "/") for x in vpath] 259 258 request.handler = LateParamPageHandler(func, *vpath) 260 259 else: trunk/cherrypy/lib/caching.py
r1278 r1288 28 28 29 29 def _key(self): 30 return cherrypy.request.config.get("tools.caching.key", cherrypy.request.browser_url) 30 return cherrypy.request.config.get("tools.caching.key", 31 cherrypy.request.browser_url) 31 32 key = property(_key) 32 33 … … 90 91 91 92 def get(): 93 request = cherrypy.request 92 94 # Ignore POST, PUT, DELETE. 93 95 # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.10. 94 invalid = cherrypy.request.config.get("tools.caching.invalid_methods",95 ("POST", "PUT", "DELETE"))96 if cherrypy.request.method in invalid:97 cherrypy.request.cached = c = False96 invalid = request.config.get("tools.caching.invalid_methods", 97 ("POST", "PUT", "DELETE")) 98 if request.method in invalid: 99 request.cached = c = False 98 100 else: 99 101 cache_data = cherrypy._cache.get() 100 cherrypy.request.cached = c = bool(cache_data)102 request.cached = c = bool(cache_data) 101 103 102 104 if c: … … 183 185 """ 184 186 187 response = cherrypy.response 188 185 189 cacheable = False 186 190 if not force: 187 191 # some header names that indicate that the response can be cached 188 192 for indicator in ('Etag', 'Last-Modified', 'Age', 'Expires'): 189 if indicator in cherrypy.response.headers:193 if indicator in response.headers: 190 194 cacheable = True 191 195 break … … 196 200 197 201 if secs == 0: 198 if force or "Pragma" not in cherrypy.response.headers:199 cherrypy.response.headers["Pragma"] = "no-cache"202 if force or "Pragma" not in response.headers: 203 response.headers["Pragma"] = "no-cache" 200 204 if cherrypy.request.protocol >= (1, 1): 201 if force or "Cache-Control" not in cherrypy.response.headers:202 cherrypy.response.headers["Cache-Control"] = "no-cache"203 204 expiry = http.HTTPDate( cherrypy.response.time + secs)205 if force or "Expires" not in cherrypy.response.headers:206 cherrypy.response.headers["Expires"] = expiry205 if force or "Cache-Control" not in response.headers: 206 response.headers["Cache-Control"] = "no-cache" 207 208 expiry = http.HTTPDate(response.time + secs) 209 if force or "Expires" not in response.headers: 210 response.headers["Expires"] = expiry trunk/cherrypy/lib/cptools.py
r1276 r1288 16 16 checks will be performed against If-Match or If-None-Match headers. 17 17 """ 18 response = cherrypy.response 19 18 20 # Guard against being run twice. 19 if hasattr( cherrypy.response, "ETag"):21 if hasattr(response, "ETag"): 20 22 return 21 23 22 etag = cherrypy.response.headers.get('ETag')24 etag = response.headers.get('ETag') 23 25 24 26 if (not etag) and autotags: 25 27 import md5 26 etag = '"%s"' % md5.new( cherrypy.response.collapse_body()).hexdigest()27 cherrypy.response.headers['ETag'] = etag28 etag = '"%s"' % md5.new(response.collapse_body()).hexdigest() 29 response.headers['ETag'] = etag 28 30 29 31 if etag: 30 cherrypy.response.ETag = etag 31 32 status, reason, msg = _http.valid_status(cherrypy.response.status) 33 34 conditions = cherrypy.request.headers.elements('If-Match') or [] 32 response.ETag = etag 33 34 status, reason, msg = _http.valid_status(response.status) 35 36 request = cherrypy.request 37 38 conditions = request.headers.elements('If-Match') or [] 35 39 conditions = [str(x) for x in conditions] 36 40 if conditions and not (conditions == ["*"] or etag in conditions): … … 38 42 raise cherrypy.HTTPError(412) 39 43 40 conditions = cherrypy.request.headers.elements('If-None-Match') or []44 conditions = request.headers.elements('If-None-Match') or [] 41 45 conditions = [str(x) for x in conditions] 42 46 if conditions == ["*"] or etag in conditions: 43 47 if status >= 200 and status < 299: 44 if cherrypy.request.method in ("GET", "HEAD"):48 if request.method in ("GET", "HEAD"): 45 49 raise cherrypy.HTTPRedirect([], 304) 46 50 else: … … 53 57 will be performed. 54 58 """ 55 lastmod = cherrypy.response.headers.get('Last-Modified') 59 response = cherrypy.response 60 lastmod = response.headers.get('Last-Modified') 56 61 if lastmod: 57 status, reason, msg = _http.valid_status(cherrypy.response.status) 58 59 since = cherrypy.request.headers.get('If-Unmodified-Since') 62 status, reason, msg = _http.valid_status(response.status) 63 64 request = cherrypy.request 65 66 since = request.headers.get('If-Unmodified-Since') 60 67 if since and since != lastmod: 61 68 if (status >= 200 and status < 299) or status == 412: 62 69 raise cherrypy.HTTPError(412) 63 70 64 since = cherrypy.request.headers.get('If-Modified-Since')71 since = request.headers.get('If-Modified-Since') 65 72 if since and since == lastmod: 66 73 if (status >= 200 and status < 299) or status == 304: 67 if cherrypy.request.method in ("GET", "HEAD"):74 if request.method in ("GET", "HEAD"): 68 75 raise cherrypy.HTTPRedirect([], 304) 69 76 else: … … 211 218 their own right. 212 219 """ 213 if hasattr(cherrypy.request, "virtual_prefix"): 220 request = cherrypy.request 221 222 if hasattr(request, "virtual_prefix"): 214 223 return 215 224 216 domain = cherrypy.request.headers.get('Host', '')225 domain = request.headers.get('Host', '') 217 226 if use_x_forwarded_host: 218 domain = cherrypy.request.headers.get("X-Forwarded-Host", domain)219 220 cherrypy.request.virtual_prefix = prefix = domains.get(domain, "")227 domain = request.headers.get("X-Forwarded-Host", domain) 228 229 request.virtual_prefix = prefix = domains.get(domain, "") 221 230 if prefix: 222 raise cherrypy.InternalRedirect(_http.urljoin(prefix, cherrypy.request.path_info))231 raise cherrypy.InternalRedirect(_http.urljoin(prefix, request.path_info)) 223 232 224 233 def log_traceback(): trunk/cherrypy/lib/wsgiapp.py
r1275 r1288 18 18 """ 19 19 20 request = cherrypy.request 21 20 22 # create and populate the wsgi environ 21 23 environ = dict() 22 24 environ["wsgi.version"] = (1,0) 23 environ["wsgi.url_scheme"] = cherrypy.request.scheme24 environ["wsgi.input"] = cherrypy.request.rfile25 environ["wsgi.url_scheme"] = request.scheme 26 environ["wsgi.input"] = request.rfile 25 27 environ["wsgi.errors"] = sys.stderr 26 28 environ["wsgi.multithread"] = True 27 29 environ["wsgi.multiprocess"] = False 28 30 environ["wsgi.run_once"] = False 29 environ["REQUEST_METHOD"] = cherrypy.request.method30 environ["SCRIPT_NAME"] = cherrypy.request.script_name31 environ["PATH_INFO"] = cherrypy.request.path_info32 environ["QUERY_STRING"] = cherrypy.request.query_string33 environ["SERVER_PROTOCOL"] = cherrypy.request.protocol34 environ["SERVER_NAME"] = cherrypy.request.local.name35 environ["SERVER_PORT"] = cherrypy.request.local.port36 environ["REMOTE_HOST"] = cherrypy.request.remote.name37 environ["REMOTE_ADDR"] = cherrypy.request.remote.ip38 environ["REMOTE_PORT"] = cherrypy.request.remote.port31 environ["REQUEST_METHOD"] = request.method 32 environ["SCRIPT_NAME"] = request.script_name 33 environ["PATH_INFO"] = request.path_info 34 environ["QUERY_STRING"] = request.query_string 35 environ["SERVER_PROTOCOL"] = request.protocol 36 environ["SERVER_NAME"] = request.local.name 37 environ["SERVER_PORT"] = request.local.port 38 environ["REMOTE_HOST"] = request.remote.name 39 environ["REMOTE_ADDR"] = request.remote.ip 40 environ["REMOTE_PORT"] = request.remote.port 39 41 # then all the http headers 40 headers = cherrypy.request.headers42 headers = request.headers 41 43 environ["CONTENT_TYPE"] = headers.get("Content-type", "") 42 44 environ["CONTENT_LENGTH"] = headers.get("Content-length", "") trunk/cherrypy/test/test_config.py
r1281 r1288 15 15 'bar': 'that'} 16 16 17 # @cherrypy.expose(alias=('global_', 'xyz')) 17 18 def index(self, key): 18 19 return cherrypy.request.config.get(key, "None") 19 index.exposed = True 20 global_ = index 21 xyz = index 20 index = cherrypy.expose(index, alias=('global_', 'xyz')) 22 21 23 22 class Foo: trunk/cherrypy/test/test_conn.py
r1286 r1288 4 4 import httplib 5 5 import socket 6 import sys 6 7 import time 7 8 … … 152 153 conn._send_output() 153 154 response = conn.response_class(conn.sock, method="GET") 154 self.assertRaises(socket.error, response.begin) 155 try: 156 response.begin() 157 except: 158 if not isinstance(sys.exc_info()[1], 159 (socket.error, httplib.BadStatusLine)): 160 self.fail("Writing to timed out socket didn't fail" 161 " as it should have: %s" % sys.exc_info()[1]) 162 else: 163 self.fail("Writing to timed out socket didn't fail" 164 " as it should have.") 155 165 156 166 conn.close()

