Last active
December 14, 2015 16:19
-
-
Save alejandrobernardis/5114273 to your computer and use it in GitHub Desktop.
Wrapp
This file contains hidden or 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
| class ValidateMethod(object): | |
| def __init__(self, *args, **kwargs): | |
| self._args = args or [] | |
| self._kwargs = kwargs or {} | |
| def __call__(self, method): | |
| def wrap(context): | |
| assert isinstance(context, ValidateMethod) | |
| def wrapper(self, *args, **kwargs): | |
| # your code here... | |
| print context._args, context._kwargs, | |
| return method(self, *args, **kwargs) | |
| return wrapper | |
| return wrap(self) | |
| class MyClass(object): | |
| @ValidateMethod(arg1, arg2) | |
| def get(self): | |
| print '...' | |
| c = MyClass() | |
| c.get() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment