Skip to content

Instantly share code, notes, and snippets.

@andreyvit
Created October 26, 2009 01:28
Show Gist options
  • Save andreyvit/218365 to your computer and use it in GitHub Desktop.
Save andreyvit/218365 to your computer and use it in GitHub Desktop.
def decorator(decorator):
def decorate(func):
def decorated(*args, **kw):
return decorator(func, *args, **kw)
return decorated
return decorate
@decorator
def decor1(func, *args, **kw):
print "before1"
r = func(*args, **kw)
print "after1"
return r
@decorator
def decor2(func, self, a, b):
print "before2: a=%s, b=%s" % (a, b)
r = func(self, a, b=b)
print "after2"
return r
@decor1
def simple(x):
return x + 1
class Foo:
@decor2
@decor1
def bar(self, a, b):
self.x = b
print "a = %s, b = %s" % (a, b)
def main():
f = Foo()
f.bar(42, simple(12))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment