I have a cherrypy application and on some of the views I want to start only allowing certain users to view them, and sending anyone else to an authorization required page.
You really don't want to be writing custom decorators for CherryPy. Instead, you want to write a new Tool:
def myauth(allowed_groups=None, debug=False):
# Do your auth here...
authlib.auth(...)
cherrypy.tools.myauth = cherrypy.Tool("on_start_resource", myauth)
See http://docs.cherrypy.org/en/latest/extend.html#tools for more discussion. This has several benefits over writing a custom decorator:
@cherrypy.tools.myauth(allowed_groups=['me'])
, and it already knows how to not clobber cherrypy.exposed on the same function._cp_config
) or per-URI-tree (in config files or dicts). You can even mix them and provide a base feature via decorators and then override their behavior in config files.