Issue #457 resolved

Regression from CP2.1 to CP2.2.0Beta on custom filter

anonymous
created an issue

Following test case (app22.py) doesn't work with CP2.2 When browser go http://localhost:8080, log window doesn't print **, that mean that MyFilter is not working. This function works well with app21.py executed with CP2.1.

{{{

!python

################ Start script app22.py
################ Executed with CP2.2 : it doesn't work

import cherrypy from cherrypy.filters.basefilter import BaseFilter

class MyFilter(BaseFilter): def beforeMain(self): print "***"

class App: def init(self): cherrypy.root = AppForm()

    cherrypy.config.update({
        'global' : {
            'server.environment' : 'development',
            'server.socket_port' : 8080,
            'server.input_filters' : ['MyFilter']
        },
    })

    cherrypy.server.start()

class AppForm: @cherrypy.expose def index(self): return "Hello"

if name == "main": App()

################ End script

}}}

{{{

!python

################ Start script app21.py (name is important)
################ Executed with CP2.1 : it works well

import cherrypy from cherrypy.lib.filter.basefilter import BaseFilter

class MyFilter(BaseFilter): def beforeMain(self): print "***"

class App: def init(self): cherrypy.root = AppForm()

    cherrypy.config.update({
        'global' : {
            'server.environment' : 'development',
            'server.socket_port' : 8080,
            'server.filtersRoot' : ["c:/alain/encours/cp"],
            'server.inputFiltersDict' : { "app21" : "MyFilter" },
        },
    })

    cherrypy.server.start()

class AppForm: @cherrypy.expose def index(self): return "Hello"

if name == "main": App()

################ End script

}}}

Comments (12)

  1. Christian Wyglendowski

    I don't think the user was advocating the use of inputFiltersDict in 2.2. That was just his example of how it worked in 2.1.

    There ''are'' some subtle issues with custom filters set in server.input_filters and server.output_filters in 2.2.

    Currently, any custom filters initialized in server.input_filters or server.output_filters must use the new underscore filter methods (i.e., before_main). This could be corrected fairly easily, and I'm willing to do it.

    Also, as in the user's 2.2 example, declaring a filter class and then passing the class name to server.input_filters as a string will cause a traceback. The string format should only be used when loading a filter class defined in another package/module. If you define the filter in the same file that you are programmaticaly setting your config, you should just pass the filter class itself to server.input_filters or server.output_filters.

    cherrypy.config.update({'global':{'server.input_filters':[MyFilter,]}})
    

    So this ticket at least requires some extra documentation and probably an update to cherrypy/filters/__init__.py. I am willing to do both.

  2. Anonymous

    This could be corrected fairly easily, and I'm willing to do it.

    Cool :)

    So this ticket at least requires some extra documentation and probably an update to cherrypy/filters/init.py. I am willing to do both.

    Double-cool :)

    How soon do you think you can get to this ? (IOW, should I wait for this before releasing CP-2.2-rc1 ?).

  3. Log in to comment