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

Changeset 1074

Show
Ignore:
Timestamp:
04/26/06 00:01:49
Author:
fumanchu
Message:

Moved the responsibility for setting response.body into the dispatch callable.

Files:

Legend:

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

    r1069 r1074  
    7777            cherrypy.response.body = [] 
    7878         
    79         _cputil.get_special_attribute("_cp_log_access", "_cpLogAccess")() 
     79        _cputil.get_special_attribute("_cp_log_access")() 
    8080         
    8181        return cherrypy.response 
     
    174174            path = self.object_path 
    175175        _dispatch = cherrypy.config.get("dispatcher") or dispatch 
    176         handler = _dispatch(path) 
    177         cherrypy.response.body = handler(*self.virtual_path, **self.params) 
     176        _dispatch(path) 
    178177     
    179178    def processHeaders(self): 
     
    236235 
    237236def dispatch(path): 
    238     """Find the appropriate page handler.""" 
     237    """Find and run the appropriate page handler.""" 
    239238    request = cherrypy.request 
    240     handler, opath, vpath = find(request.browser_url, path) 
     239    handler, opath, vpath = find(path) 
    241240     
    242241    # Remove "root" from opath and join it to get found_object_path 
    243     request.found_object_path = '/' + '/'.join(opath[1:]) 
     242    # There are no consumers of this info right now, so this block 
     243    # may disappear soon. 
     244    if opath and opath[0] == "root": 
     245        opath.pop(0) 
     246    request.found_object_path = '/' + '/'.join(opath) 
    244247     
    245248    # Decode any leftover %2F in the virtual_path atoms. 
    246     request.virtual_path = [x.replace("%2F", "/") for x in vpath] 
    247      
    248     return handler 
    249  
    250 def find(browser_url, objectpath): 
     249    vpath = [x.replace("%2F", "/") for x in vpath] 
     250    cherrypy.response.body = handler(*vpath, **request.params) 
     251 
     252def find(objectpath): 
    251253    objectTrail = _cputil.get_object_trail(objectpath) 
    252254    names = [name for name, candidate in objectTrail] 
     
    272274                # had a trailing slash (otherwise, do a redirect). 
    273275                if not objectpath.endswith('/'): 
    274                     atoms = browser_url.split("?", 1) 
     276                    atoms = cherrypy.request.browser_url.split("?", 1) 
    275277                    newUrl = atoms.pop(0) + '/' 
    276278                    if atoms: 
     
    392394            cherrypy.request.hooks.run('before_error_response') 
    393395             
    394             self.error_response() 
     396            _cputil.get_special_attribute('_cp_on_error')() 
    395397            self.finalize() 
    396398             
     
    413415            pass 
    414416         
    415         # Failure in self.error_response, error hooks, or finalize. 
     417        # Failure in error hooks or finalize. 
    416418        # Bypass them all. 
    417419        if cherrypy.config.get('server.show_tracebacks', False): 
     
    422424        self.setBareError(body) 
    423425     
    424     def error_response(self): 
    425         # _cp_on_error will probably change self.body. 
    426         # It may also change the headers, etc. 
    427         _cputil.get_special_attribute('_cp_on_error', '_cpOnError')() 
    428      
    429426    def setBareError(self, body=None): 
    430427        self.status, self.header_list, self.body = _cputil.bareError(body) 
  • trunk/cherrypy/test/test_core.py

    r1069 r1074  
    487487            data = open(log_file, "rb").readlines() 
    488488            self.assertEqual(data[0][-41:], ' INFO Traceback (most recent call last):\n') 
    489             self.assertEqual(data[6], '    raise ValueError()\n') 
     489            self.assertEqual(data[-3], '    raise ValueError()\n') 
    490490             
    491491            # Test that unhandled tracebacks get written to the error log 
     
    494494            self.assertInBody("raise ValueError()") 
    495495            data = open(log_file, "rb").readlines() 
    496             self.assertEqual(data[9][-41:], ' INFO Traceback (most recent call last):\n') 
    497             self.assertEqual(data[15], '    raise ValueError()\n') 
    498             # Each error should write only one traceback (9 lines each). 
    499             self.assertEqual(len(data), 18) 
     496            self.assertEqual(data[-3], '    raise ValueError()\n') 
     497            # Each error should write only one traceback (11 lines each). 
     498            self.assertEqual(len(data), 22) 
    500499        finally: 
    501500            ignore.pop() 

Hosted by WebFaction

Log in as guest/cpguest to create tickets