Ticket #548: before_handler.patch
-
test/test_core.py
old new 136 136 def login_redir(): 137 137 if not getattr(cherrypy.request, "login", None): 138 138 raise cherrypy.InternalRedirect("/internalredirect/login") 139 tools.login_redir = _cptools.Tool('before_ main', login_redir)139 tools.login_redir = _cptools.Tool('before_handler', login_redir) 140 140 141 141 class InternalRedirect(Test): 142 142 -
_cprequest.py
old new 87 87 config = None 88 88 error_response = cherrypy.HTTPError(500).set_response 89 89 hookpoints = ['on_start_resource', 'before_request_body', 90 'before_ main', 'before_finalize',90 'before_handler', 'before_finalize', 91 91 'on_end_resource', 'on_end_request', 92 92 'before_error_response', 'after_error_response'] 93 93 hooks = HookMap(hookpoints) … … 236 236 if self.process_request_body: 237 237 self.process_body() 238 238 239 self.hooks.run('before_ main')239 self.hooks.run('before_handler') 240 240 if self.handler: 241 241 self.handler() 242 242 self.hooks.run('before_finalize') -
lib/caching.py
old new 164 164 conf = cherrypy.request.toolmap.get("caching", {}) 165 165 if not getattr(cherrypy, "_cache", None): 166 166 init(conf.get("class", None)) 167 cherrypy.request.hooks.attach('before_ main', _wrapper)167 cherrypy.request.hooks.attach('before_handler', _wrapper) 168 168 169 169 def expires(secs=0, force=False): 170 170 """Tool for influencing cache mechanisms using the 'Expires' header. -
_cptools.py
old new 95 95 cherrypy.request.hooks.attach(self._point, self.callable, conf) 96 96 97 97 98 class MainTool(Tool):99 """Tool which is called 'before main', that may skip normal handlers.98 class HandlerTool(Tool): 99 """Tool which is called 'before handler', that may skip normal handlers. 100 100 101 101 The callable provided should return True if processing should skip 102 102 the normal page handler, and False if it should not. 103 103 """ 104 104 105 105 def __init__(self, callable, name=None): 106 Tool.__init__(self, 'before_ main', callable, name)106 Tool.__init__(self, 'before_handler', callable, name) 107 107 108 108 def handler(self, *args, **kwargs): 109 109 """Use this tool as a CherryPy page handler. … … 226 226 raise cherrypy.InternalRedirect(ppath) 227 227 228 228 229 class WSGIAppTool( MainTool):229 class WSGIAppTool(HandlerTool): 230 230 """A tool for running any WSGI middleware/application within CP. 231 231 232 232 Here are the parameters: … … 247 247 def _setup(self): 248 248 # Keep request body intact so the wsgi app can have its way with it. 249 249 cherrypy.request.process_request_body = False 250 MainTool._setup(self)250 HandlerTool._setup(self) 251 251 252 252 253 253 class CachingTool: … … 270 270 271 271 272 272 default_toolbox = Toolbox() 273 default_toolbox.session_auth = MainTool(cptools.session_auth)273 default_toolbox.session_auth = HandlerTool(cptools.session_auth) 274 274 default_toolbox.proxy = Tool('before_request_body', cptools.proxy) 275 275 default_toolbox.response_headers = Tool('on_start_resource', cptools.response_headers) 276 276 # We can't call virtual_host in on_start_resource, … … 280 280 default_toolbox.log_headers = Tool('before_error_response', cptools.log_request_headers) 281 281 default_toolbox.err_redirect = ErrorTool(cptools.redirect) 282 282 default_toolbox.etags = Tool('before_finalize', cptools.validate_etags) 283 default_toolbox.decode = Tool('before_ main', encoding.decode)283 default_toolbox.decode = Tool('before_handler', encoding.decode) 284 284 default_toolbox.encode = Tool('before_finalize', encoding.encode) 285 285 default_toolbox.gzip = Tool('before_finalize', encoding.gzip) 286 default_toolbox.staticdir = MainTool(static.staticdir)287 default_toolbox.staticfile = MainTool(static.staticfile)286 default_toolbox.staticdir = HandlerTool(static.staticdir) 287 default_toolbox.staticfile = HandlerTool(static.staticfile) 288 288 # _sessions.init must be bound after headers are read 289 289 default_toolbox.sessions = SessionTool('before_request_body', _sessions.init) 290 290 default_toolbox.xmlrpc = XMLRPCTool()

