Issue #1014 invalid

default handler breaks url mapping when used as a function attribute instead of a class attribute

Anonymous created an issue

From the info given at: http://www.cherrypy.org/wiki/CherryPyTutorial#Partialmatchesandthedefaultmethod

It may be easiest to explain via a small code example as below.

The "Method" behaviour appears to be buggy, where as the "Class" behaviour is as expected.

EXAMPLE: {{{ import cherrypy

def defaultHandler(*args): return "=Default" defaultHandler.exposed = True

def Method(*args): return "=Method" Method.exposed = True

def MethodWithDefault(*args): return "=MethodWidthDefault" MethodWithDefault.exposed = True MethodWithDefault.default = defaultHandler

class Class(object): def index(self): return "=Class" index.exposed = True

class ClassWithDefault(object): def index(self): return "=ClassWithDefault" index.exposed = True default = defaultHandler

class HelloWorld(object): def index(self): return "Hello World!" index.exposed = True Method = Method MethodWithDefault = MethodWithDefault Class = Class() ClassWithDefault = ClassWithDefault()

cherrypy.quickstart(HelloWorld())

http://localhost:8080/Class/

=Class

http://localhost:8080/ClassWithDefault/

=ClassWithDefault

http://localhost:8080/ClassWithDefault/random_string

=Default

http://localhost:8080/Method/

=Method

http://localhost:8080/MethodWithDefault/

=Default <-- NOT WHAT I EXPECTED!! What's going on here???

http://localhost:8080/MethodWithDefault/random_string

=Default

}}}

Reported by tim@io41.com

Comments (2)

  1. Joel Rivera

    The index method is "special" to make a fair comparison on your example that will be:

    import cherrypy
    
    
    def defaultHandler(*args):
        return "=Default"
    defaultHandler.exposed = True
    
    
    def Method(*args):
        return "=Method"
    Method.exposed = True
    
    
    def MethodWithDefault(*args):
        return "=MethodWidthDefault"
    MethodWithDefault.exposed = True
    MethodWithDefault.default = defaultHandler
    
    
    class Class(object):
        exposed = True
        def __call__(self):
            return "=Class"
    
    class ClassWithDefault(object):
         exposed = True
        def __call__(self):
            return "=ClassWithDefault"
        default = defaultHandler
    
    
    class HelloWorld(object):
    
        def index(self):
            return "Hello World!"
        index.exposed = True
        Method = Method
        MethodWithDefault = MethodWithDefault
        Class = Class()
        ClassWithDefault = ClassWithDefault()
    
    cherrypy.quickstart(HelloWorld())
    

    And it will yield the same results.

  2. Log in to comment