Skip to content

Instantly share code, notes, and snippets.

@quephird
Created March 23, 2012 01:52
Show Gist options
  • Save quephird/2166133 to your computer and use it in GitHub Desktop.
Save quephird/2166133 to your computer and use it in GitHub Desktop.
AOP in Python using logilab library
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