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
bb-migration opened this Issue Apr 15, 2014 · 0 comments

Comments

Projects
None yet
1 participant
@bb-migration

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

coady added a commit to coady/cherrypy that referenced this issue May 2, 2016

coady added a commit to coady/cherrypy that referenced this issue May 2, 2016

coady added a commit to coady/cherrypy that referenced this issue May 5, 2016

@jaraco jaraco closed this in dff09e9 Jun 5, 2016

jaraco added a commit that referenced this issue Jun 5, 2016

Merge pull request #1428 from coady/master
Fix #1311: decorator for registering tools.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment