Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #457 (defect)

Opened 3 years ago

Last modified 3 years ago

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

Status: closed (fixed)

Reported by: anonymous Assigned to: dowski
Priority: normal Milestone: 2.2-final
Component: CherryPy code Keywords:
Cc:

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.

###################### 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
###################### 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

Change History

02/02/06 07:40:04: Modified by dowski

  • description changed.

wiki-formatted the pasted code samples

02/17/06 11:11:39: Modified by rdelon

  • milestone changed from 2.2-beta to 2.1-rc1.

02/21/06 13:18:03: Modified by dowski

  • milestone changed from 2.1-rc1 to 2.2-rc1.

02/28/06 09:33:10: Modified by rdelon

  • status changed from new to closed.
  • resolution set to wontfix.

The use of inputFiltersDict is not recommended

03/01/06 08:40:18: Modified by dowski

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 2.2-rc1 to 2.2-final.

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.

03/01/06 08:50:59: Modified by rdelon

> 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 ?).

03/01/06 09:21:21: Modified by dowski

  • owner changed from rdelon to dowski.
  • status changed from reopened to new.

03/01/06 09:22:27: Modified by dowski

  • status changed from new to closed.
  • resolution set to fixed.

Fixed in [985].

Hosted by WebFaction

Log in as guest/cpguest to create tickets