Skip to content

Decorator for registering tools. #1311

@ghost

Description

Originally reported by: coady (Bitbucket: coady, GitHub: coady)


For simple function tools, they're almost always registered immediately after defining them, using the same name. Even the example in the docs:

#!python
def protect(users):
    if cherrypy.request.login not in users:
        raise cherrypy.HTTPError("401 Unauthorized")
cherrypy.tools.protect = Tool('on_start_resource', protect)

This pattern seems like a perfect use case for a decorator. Such as:

#!python
@cherrypy.tools.register('on_start_resource')
def protect(users):
    if cherrypy.request.login not in users:
        raise cherrypy.HTTPError("401 Unauthorized")

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions