Created
October 15, 2015 17:20
-
-
Save mwhagedorn/3d4b49f93847f545687a to your computer and use it in GitHub Desktop.
an example of nested decorators in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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