Changeset 1080
- Timestamp:
- 04/26/06 18:54:11
- Files:
-
- trunk/cherrypy/_cprequest.py (modified) (2 diffs)
- trunk/cherrypy/_cputil.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cprequest.py
r1078 r1080 87 87 # right away. 88 88 self.processRequestLine() 89 self.dispatch = cherrypy.config.get("dispatch") or dispatch89 self.dispatch = cherrypy.config.get("dispatch") or _cputil.dispatch 90 90 self.hooks.setup() 91 91 … … 227 227 228 228 229 def dispatch(path):230 """Find and run the appropriate page handler."""231 request = cherrypy.request232 handler, opath, vpath = find_handler(path)233 234 # Remove "root" from opath and join it to get found_object_path235 # There are no consumers of this info right now, so this block236 # may disappear soon.237 if opath and opath[0] == "root":238 opath.pop(0)239 request.found_object_path = '/' + '/'.join(opath)240 241 # Decode any leftover %2F in the virtual_path atoms.242 vpath = [x.replace("%2F", "/") for x in vpath]243 cherrypy.response.body = handler(*vpath, **request.params)244 245 def find_handler(objectpath):246 """Find the appropriate page handler for the given path."""247 objectTrail = _cputil.get_object_trail(objectpath)248 names = [name for name, candidate in objectTrail]249 250 # Try successive objects (reverse order)251 mounted_app_roots = cherrypy.tree.mount_points.values()252 for i in xrange(len(objectTrail) - 1, -1, -1):253 254 name, candidate = objectTrail[i]255 256 # Try a "default" method on the current leaf.257 defhandler = getattr(candidate, "default", None)258 if callable(defhandler) and getattr(defhandler, 'exposed', False):259 return defhandler, names[:i+1] + ["default"], names[i+1:-1]260 261 # Uncomment the next line to restrict positional params to "default".262 # if i < len(objectTrail) - 2: continue263 264 # Try the current leaf.265 if callable(candidate) and getattr(candidate, 'exposed', False):266 if i == len(objectTrail) - 1:267 # We found the extra ".index". Check if the original path268 # had a trailing slash (otherwise, do a redirect).269 if not objectpath.endswith('/'):270 atoms = cherrypy.request.browser_url.split("?", 1)271 newUrl = atoms.pop(0) + '/'272 if atoms:273 newUrl += "?" + atoms[0]274 raise cherrypy.HTTPRedirect(newUrl)275 return candidate, names[:i+1], names[i+1:-1]276 277 if candidate in mounted_app_roots:278 break279 280 # We didn't find anything281 raise cherrypy.NotFound(objectpath)282 283 284 229 class Body(object): 285 230 """The body of the HTTP response (the response entity).""" trunk/cherrypy/_cputil.py
r1078 r1080 59 59 60 60 return objectTrail 61 62 def dispatch(path): 63 """Find and run the appropriate page handler.""" 64 request = cherrypy.request 65 handler, opath, vpath = find_handler(path) 66 67 # Remove "root" from opath and join it to get found_object_path 68 # There are no consumers of this info right now, so this block 69 # may disappear soon. 70 if opath and opath[0] == "root": 71 opath.pop(0) 72 request.found_object_path = '/' + '/'.join(opath) 73 74 # Decode any leftover %2F in the virtual_path atoms. 75 vpath = [x.replace("%2F", "/") for x in vpath] 76 cherrypy.response.body = handler(*vpath, **request.params) 77 78 def find_handler(objectpath): 79 """Find the appropriate page handler for the given path.""" 80 objectTrail = get_object_trail(objectpath) 81 names = [name for name, candidate in objectTrail] 82 83 # Try successive objects (reverse order) 84 mounted_app_roots = cherrypy.tree.mount_points.values() 85 for i in xrange(len(objectTrail) - 1, -1, -1): 86 87 name, candidate = objectTrail[i] 88 89 # Try a "default" method on the current leaf. 90 defhandler = getattr(candidate, "default", None) 91 if callable(defhandler) and getattr(defhandler, 'exposed', False): 92 return defhandler, names[:i+1] + ["default"], names[i+1:-1] 93 94 # Uncomment the next line to restrict positional params to "default". 95 # if i < len(objectTrail) - 2: continue 96 97 # Try the current leaf. 98 if callable(candidate) and getattr(candidate, 'exposed', False): 99 if i == len(objectTrail) - 1: 100 # We found the extra ".index". Check if the original path 101 # had a trailing slash (otherwise, do a redirect). 102 if not objectpath.endswith('/'): 103 atoms = cherrypy.request.browser_url.split("?", 1) 104 newUrl = atoms.pop(0) + '/' 105 if atoms: 106 newUrl += "?" + atoms[0] 107 raise cherrypy.HTTPRedirect(newUrl) 108 return candidate, names[:i+1], names[i+1:-1] 109 110 if candidate in mounted_app_roots: 111 break 112 113 # We didn't find anything 114 raise cherrypy.NotFound(objectpath) 115 61 116 62 117 def get_special_attribute(name):

