Created
October 26, 2009 01:28
-
-
Save andreyvit/218365 to your computer and use it in GitHub Desktop.
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
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