Changeset 376
- Timestamp:
- 06/24/05 12:29:34
- Files:
-
- trunk/cherrypy/_cphttptools.py (modified) (1 diff)
- trunk/cherrypy/cperror.py (modified) (1 diff)
- trunk/cherrypy/lib/cptools.py (modified) (previous)
- trunk/cherrypy/test/test_core.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/_cphttptools.py
r371 r376 332 332 return 333 333 except cperror.InternalRedirect, x: 334 # Set the path to the new one (provided in the exception) 335 # and try again. 336 path = x.args[0] 334 # Try again with the new path 335 path = x.path 337 336 338 337 def iterable(body): trunk/cherrypy/cperror.py
r371 r376 56 56 57 57 class InternalRedirect(Exception): 58 """Exception raised when processing should be handled by a different path.""" 59 pass 58 """Exception raised when processing should be handled by a different path. 59 60 If you supply a queryString, it will be used to re-populate paramMap. 61 62 If you omit queryString, the paramMap from the original request will 63 remain in effect, including any POST parameters. 64 """ 65 66 def __init__(self, path, queryString=None): 67 from cherrypy import cpg 68 import cgi 69 70 self.path = path 71 if queryString is not None: 72 cpg.request.queryString = queryString 73 74 pm = cgi.parse_qs(cpg.request.queryString, keep_blank_values=True) 75 for key, val in pm.items(): 76 if len(val) == 1: 77 pm[key] = val[0] 78 cpg.request.paramMap = pm 79 80 cpg.request.browserUrl = cpg.request.base + path 81 82 60 83 61 84 class HTTPRedirect(Exception): trunk/cherrypy/test/test_core.py
r371 r376 94 94 def internal(self): 95 95 raise cperror.InternalRedirect("/") 96 97 def internal2(self, user_id): 98 if user_id == "parrot": 99 # Trade it for a slug when redirecting 100 raise cperror.InternalRedirect('/image/getImagesByUser', 101 "user_id=slug") 102 else: 103 raise cperror.InternalRedirect('/image/getImagesByUser') 104 105 106 class Image(Test): 107 108 def getImagesByUser(self, user_id): 109 return "0 images for %s" % user_id 96 110 97 111 … … 272 286 self.assertEqual(cpg.response.body, 'hello') 273 287 self.assertEqual(cpg.response.status, '200 OK') 288 289 helper.request("/redirect/internal2?user_id=Sir-not-appearing-in-this-film") 290 self.assertEqual(cpg.response.body, '0 images for Sir-not-appearing-in-this-film') 291 self.assertEqual(cpg.response.status, '200 OK') 292 293 helper.request("/redirect/internal2?user_id=parrot") 294 self.assertEqual(cpg.response.body, '0 images for slug') 295 self.assertEqual(cpg.response.status, '200 OK') 274 296 275 297 def testFlatten(self):

