Anonymous avatar Anonymous committed cbe58ef

Fix for #457. Custom filters placed in {{{server.input_filters}}} and {{{server.ouput_filters}}} now get checked for the presence of the old camelCase filter hooks at initialization for backward compatibility with 2.1.

Comments (0)

Files changed (1)

cherrypy/filters/__init__.py

 _output_methods = ['before_finalize', 'on_end_resource', 'on_end_request',
         'before_error_response', 'after_error_response']
 
+_old_input_methods = ['onStartResource', 'beforeRequestBody', 'beforeMain']
+_old_output_methods = ['beforeFinalize', 'onEndResource', 'onEndRequest',
+        'beforeErrorResponse', 'afterErrorResponse']
+
 backward_compatibility_dict = {
     'on_start_resource': 'onStartResource',
     'before_request_body': 'beforeRequestBody',
         outputs.append(f)
     
     # Transform the instance lists into a dict of methods
+    # in 2.2 we check the old camelCase filter names first
+    # to provide backward compatibility with 2.1
     _filterhooks.clear()
-    for name in _input_methods:
-        _filterhooks[name] = []
+    for old_name, new_name in zip(_old_input_methods, _input_methods):
+        _filterhooks[new_name] = []
         for f in inputs:
-            method = getattr(f, name, None)
+            method = getattr(f, old_name, None)
             if method:
-                _filterhooks[name].append(method)
-    for name in _output_methods:
-        _filterhooks[name] = []
+                _filterhooks[new_name].append(method)
+            else:
+                method = getattr(f, new_name, None)
+                if method:
+                    _filterhooks[new_name].append(method)
+    for old_name, new_name in zip(_old_output_methods, _output_methods):
+        _filterhooks[new_name] = []
         for f in outputs:
-            method = getattr(f, name, None)
+            method = getattr(f, old_name, None)
             if method:
-                _filterhooks[name].append(method)
+                _filterhooks[new_name].append(method)
+            else:
+                method = getattr(f, new_name, None)
+                if method:
+                    _filterhooks[new_name].append(method)
 
 
 _filterhooks = {}
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.