Skip to content

Instantly share code, notes, and snippets.

@alejandrobernardis
Last active December 14, 2015 16:19
Show Gist options
  • Select an option

  • Save alejandrobernardis/5114273 to your computer and use it in GitHub Desktop.

Select an option

Save alejandrobernardis/5114273 to your computer and use it in GitHub Desktop.
Wrapp
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