Commits

Robert Brewer  committed d1aaee3

Fix to tool priorities.

  • Participants
  • Parent commits e4fb5cd

Comments (0)

Files changed (3)

File cherrypy/_cptools.py

         The standard CherryPy request object will automatically call this
         method when the tool is "turned on" in config.
         """
-        conf = self._merged_args()
-        cherrypy.request.hooks.attach(self._point, self.callable, **conf)
+        f = getattr(self.callable, "failsafe", False)
+        p = getattr(self.callable, "priority", self._priority)
+        cherrypy.request.hooks.attach(self._point, self.callable, failsafe=f,
+                                      priority=p, **self._merged_args())
 
 
 class HandlerTool(Tool):
 
 default_toolbox = _d = Toolbox()
 default_toolbox.session_auth = SessionAuthTool(cptools.session_auth)
-_d.proxy = Tool('before_request_body',
-                             cptools.proxy, priority=30)
+_d.proxy = Tool('before_request_body', cptools.proxy, priority=30)
 _d.response_headers = Tool('on_start_resource', cptools.response_headers)
 # We can't call virtual_host in on_start_resource,
 # because it's failsafe and the redirect would be swallowed.
-_d.virtual_host = Tool('before_request_body',
-                                    cptools.virtual_host, priority=40)
+_d.virtual_host = Tool('before_request_body', cptools.virtual_host, priority=40)
 _d.log_tracebacks = Tool('before_error_response', cptools.log_traceback)
 _d.log_headers = Tool('before_error_response', cptools.log_request_headers)
 _d.err_redirect = ErrorTool(cptools.redirect)

File cherrypy/lib/encoding.py

         else:
             raise cherrypy.HTTPError(500, failmsg % encoding)
     
-    # Parse the Accept_Charset request header, and try to provide one
+    # Parse the Accept-Charset request header, and try to provide one
     # of the requested charsets (in order of user preference).
     encs = cherrypy.request.headers.elements('Accept-Charset')
     if not encs:

File cherrypy/test/test_tools.py

         index.exposed = True
         
         def euro(self):
+            hooks = list(cherrypy.request.hooks['before_finalize'])
+            hooks.sort()
+            assert [x.callback.__name__ for x in hooks] == ['encode', 'gzip']
+            assert [x.priority for x in hooks] == [70, 80]
             yield u"Hello,"
             yield u"world"
             yield europoundUnicode
         zfile.write(expectedResult)
         zfile.close()
         
-        self.getPage("/euro", headers=[("Accept-Encoding", "gzip")])
+        self.getPage("/euro", headers=[("Accept-Encoding", "gzip"),
+                                        ("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7")])
         self.assertInBody(zbuf.getvalue()[:3])
         
         zbuf = StringIO.StringIO()