Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decorator for registering tools. #1311

Closed
ghost opened this issue Apr 15, 2014 · 0 comments
Closed

Decorator for registering tools. #1311

ghost opened this issue Apr 15, 2014 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 15, 2014

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")

@jaraco jaraco closed this as completed in dff09e9 Jun 5, 2016
jaraco added a commit that referenced this issue Jun 5, 2016
Fix #1311: decorator for registering tools.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants