Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Changeset 1400

Show
Ignore:
Timestamp:
10/19/06 01:13:17
Author:
fumanchu
Message:

Applied suggested patch to #584 (Need a way to get the url submitted to a InternalRedirect?). See the ticket for details.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cherrypy/__init__.py

    r1393 r1400  
    168168    Finally, note that this function can be used to obtain an absolute URL 
    169169    for the current request path (minus the querystring) by passing no args. 
     170    If you call url(qs=cherrypy.request.query_string), you should get the 
     171    original browser URL (assuming no Internal redirections). 
    170172    """ 
    171173    if qs: 
  • trunk/cherrypy/_cperror.py

    r1350 r1400  
    1111 
    1212class InternalRedirect(CherryPyException): 
    13     """Exception raised when processing should be handled by a different path
     13    """Exception raised to switch to the handler for a different URL
    1414     
    1515    If you supply a query string, it will replace request.params. 
    16     If you omit the query string, the params from the original request will 
    17     remain in effect. 
     16    If you omit the query string (no question mark), the params from the 
     17    original request will remain in effect. 
     18    To erase any query string parameters, write url + "?" with no params. 
    1819    """ 
    1920     
     
    2223        request = cherrypy.request 
    2324         
     25        self.query_string = "" 
    2426        if "?" in path: 
    25             # Pop any params included in the path 
    26             path, pm = path.split("?", 1) 
    27             request.query_string = pm 
    28             request.params = _http.parse_query_string(pm) 
     27            # Separate any params included in the path 
     28            path, self.query_string = path.split("?", 1) 
    2929         
    3030        # Note that urljoin will "do the right thing" whether url is: 
     
    3838        self.path = path 
    3939         
    40         CherryPyException.__init__(self, path) 
    41  
     40        CherryPyException.__init__(self, path, self.query_string) 
    4241 
    4342 
  • trunk/cherrypy/_cprequest.py

    r1390 r1400  
    287287            # Loop to allow for InternalRedirect. 
    288288            pi = self.path_info 
     289            qs = self.query_string 
    289290            while True: 
    290291                try: 
     
    292293                    break 
    293294                except cherrypy.InternalRedirect, ir: 
    294                     pi = ir.path 
    295                     if pi in self.redirections and not self.recursive_redirect
     295                    if (ir.path in self.redirections 
     296                        and not self.recursive_redirect)
    296297                        raise RuntimeError("InternalRedirect visited the " 
    297                                            "same URL twice: %s" % repr(pi)) 
    298                     self.redirections.append(pi) 
     298                                           "same URL twice: %s" % repr(ir.path)) 
     299                     
     300                    # Add the *previous* path_info + qs to self.redirections. 
     301                    if qs: 
     302                        qs = "?" + qs 
     303                    self.redirections.append(pi + qs) 
     304                     
     305                    pi = self.path_info = ir.path 
     306                    qs = self.query_string = ir.query_string 
     307                    if qs: 
     308                        self.params = http.parse_query_string(qs) 
    299309        except (KeyboardInterrupt, SystemExit): 
    300310            raise 
  • trunk/cherrypy/test/test_core.py

    r1369 r1400  
    161161            raise cherrypy.InternalRedirect("/") 
    162162         
    163         def relative(self): 
    164             raise cherrypy.InternalRedirect("cousin") 
    165          
    166         def cousin(self): 
    167             return "I am a redirected page." 
     163        def relative(self, a, b): 
     164            raise cherrypy.InternalRedirect("cousin?t=6") 
     165         
     166        def cousin(self, t): 
     167            return repr(cherrypy.request.redirections + 
     168                        [cherrypy.url(qs=cherrypy.request.query_string)]) 
    168169         
    169170        def petshop(self, user_id): 
     
    176177                raise cherrypy.InternalRedirect('/image/getImagesByUser') 
    177178            else: 
     179                # This should pass the user_id through to getImagesByUser 
    178180                raise cherrypy.InternalRedirect('/image/getImagesByUser') 
    179181         
     
    603605        self.assertStatus(200) 
    604606         
    605         # Relative path in InternalRedirect 
    606         self.getPage("/internalredirect/relative") 
    607         self.assertBody('I am a redirected page.') 
     607        # Relative path in InternalRedirect. 
     608        # Also tests request.redirections 
     609        self.getPage("/internalredirect/relative?a=3&b=5") 
     610        self.assertBody("['/internalredirect/relative?a=3&b=5', " 
     611                        "'%s/internalredirect/cousin?t=6']" % self.base()) 
    608612        self.assertStatus(200) 
    609613         

Hosted by WebFaction

Log in as guest/cpguest to create tickets