Skip to content

Instantly share code, notes, and snippets.

@mwhagedorn
Created October 15, 2015 17:20
Show Gist options
  • Save mwhagedorn/3d4b49f93847f545687a to your computer and use it in GitHub Desktop.
Save mwhagedorn/3d4b49f93847f545687a to your computer and use it in GitHub Desktop.
an example of nested decorators in python
def composite_decorator(self, func, **kwargs):
'''Create a composite decorator
:return: a composite decorator which applies each decorator defined
in self.url_decorators. Should be like calling one decorator
my_decorator(view_func, dashboard=None, panel=None):
'''
def new_decorator(func, **kwargs ):
for decorator in reversed(self.url_decorators):
func = decorator(func)
@functools.wraps(func)
def wrapped(*args,**kwargs):
return func(*args,**kwargs)
return wrapped
return new_decorator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment