Created
March 23, 2012 01:52
-
-
Save quephird/2166133 to your computer and use it in GitHub Desktop.
AOP in Python using logilab library
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
from logilab.aspects.core import AbstractAspect | |
from logilab.aspects.weaver import weaver | |
class MyAspect(AbstractAspect): | |
def before(self, wobj, context, *args, **kwargs): | |
print "Before", context['method_name'] | |
def after(self, wobj, context, *args, **kwargs): | |
print "After", context['method_name'] | |
class Foo: | |
def bar(self): | |
print "In bar" | |
def baz(self): | |
print "In baz" | |
def quux(self): | |
print "In quux" | |
weaver.weave_methods(Foo, MyAspect) | |
foo = Foo() | |
foo.bar() | |
foo.baz() | |
foo.quux() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment