Robert Brewer avatar Robert Brewer committed a77d0bd

Fix for #548 (Rename the before_main hook to before_handler and MainTool to HandlerTool).

Comments (0)

Files changed (4)

cherrypy/_cprequest.py

     redirect_on_missing_slash = True
     
     hookpoints = ['on_start_resource', 'before_request_body',
-                  'before_main', 'before_finalize',
+                  'before_handler', 'before_finalize',
                   'on_end_resource', 'on_end_request',
                   'before_error_response', 'after_error_response']
     hooks = HookMap(hookpoints)
                     if self.process_request_body:
                         self.process_body()
                     
-                    self.hooks.run('before_main')
+                    self.hooks.run('before_handler')
                     if self.handler:
                         self.handler()
                     self.hooks.run('before_finalize')
     def _set_hook(self, k, v):
         """Attach bare hooks declared in config."""
         # Use split again to allow multiple hooks for a single
-        # hookpoint per path (e.g. "hooks.before_main.1").
+        # hookpoint per path (e.g. "hooks.before_handler.1").
         # Little-known fact you only get from reading source ;)
         hookpoint = k.split(".", 1)[0]
         if isinstance(v, basestring):

cherrypy/_cpserver.py

         self.interrupt = None
     
     def quickstart(self, server=None):
-        """Main function for quick starts. MUST be called from the main thread.
+        """Start from defaults. MUST be called from the main thread.
         
         This function works like CherryPy 2's server.start(). It loads and
         starts an httpserver based on the given server object (if provided)

cherrypy/_cptools.py

         cherrypy.request.hooks.attach(self._point, self.callable, **conf)
 
 
-class MainTool(Tool):
+class HandlerTool(Tool):
     """Tool which is called 'before main', that may skip normal handlers.
     
     The callable provided should return True if processing should skip
     """
     
     def __init__(self, callable, name=None):
-        Tool.__init__(self, 'before_main', callable, name)
+        Tool.__init__(self, 'before_handler', callable, name)
     
     def handler(self, *args, **kwargs):
         """Use this tool as a CherryPy page handler.
             raise cherrypy.InternalRedirect(ppath)
 
 
-class WSGIAppTool(MainTool):
+class WSGIAppTool(HandlerTool):
     """A tool for running any WSGI middleware/application within CP.
     
     Here are the parameters:
     def _setup(self):
         # Keep request body intact so the wsgi app can have its way with it.
         cherrypy.request.process_request_body = False
-        MainTool._setup(self)
+        HandlerTool._setup(self)
 
 
-class SessionAuthTool(MainTool):
+class SessionAuthTool(HandlerTool):
     
     def _setargs(self):
         for name in dir(cptools.SessionAuth):
     def _setup(self):
         """Hook caching into cherrypy.request."""
         conf = self._merged_args()
-        cherrypy.request.hooks.attach('before_main', self._wrapper, **conf)
+        cherrypy.request.hooks.attach('before_handler', self._wrapper, **conf)
 
 
 
 default_toolbox.log_headers = Tool('before_error_response', cptools.log_request_headers)
 default_toolbox.err_redirect = ErrorTool(cptools.redirect)
 default_toolbox.etags = Tool('before_finalize', cptools.validate_etags)
-default_toolbox.decode = Tool('before_main', encoding.decode)
+default_toolbox.decode = Tool('before_handler', encoding.decode)
 default_toolbox.encode = Tool('before_finalize', encoding.encode)
 default_toolbox.gzip = Tool('before_finalize', encoding.gzip)
-default_toolbox.staticdir = MainTool(static.staticdir)
-default_toolbox.staticfile = MainTool(static.staticfile)
+default_toolbox.staticdir = HandlerTool(static.staticdir)
+default_toolbox.staticfile = HandlerTool(static.staticfile)
 # _sessions.init must be bound after headers are read
 default_toolbox.sessions = SessionTool('before_request_body', _sessions.init)
 default_toolbox.xmlrpc = XMLRPCTool()
 default_toolbox.wsgiapp = WSGIAppTool(_wsgiapp.run)
-default_toolbox.caching = CachingTool('before_main', _caching.get, 'caching')
+default_toolbox.caching = CachingTool('before_handler', _caching.get, 'caching')
 default_toolbox.expires = Tool('before_finalize', _caching.expires)
 default_toolbox.tidy = Tool('before_finalize', tidy.tidy)
 default_toolbox.nsgmls = Tool('before_finalize', tidy.nsgmls)

cherrypy/test/test_core.py

     def login_redir():
         if not getattr(cherrypy.request, "login", None):
             raise cherrypy.InternalRedirect("/internalredirect/login")
-    tools.login_redir = _cptools.Tool('before_main', login_redir)
+    tools.login_redir = _cptools.Tool('before_handler', login_redir)
     
     def redir_custom():
         raise cherrypy.InternalRedirect("/internalredirect/custom_err")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.