wrapping a method function call?
gregturn at mindspring.com
Tue Nov 4 19:15:12 CET 2008
Spring Python provides an AOP solution (http://
springpython.webfactional.com/reference/html/aop.html). You can define
regexp patterns of what you want to intercept.
Imagine having this service:
def method(self, data):
return "You sent me '%s'" % data
return "Okay, I'm doing something"
You can write a simple interceptor that wraps the results:
from springpython.aop import *
"""Interceptor that is called before the real method, and has
access afterwards to the results
def invoke(self, invocation):
results = "<Wrapped>" + invocation.proceed() + "</Wrapped>"
Simply creating an instance of your base class acts as you would
service = SampleService()
>>> "You sent me 'something'"
Change one line, and your interceptor is plugged in:
service = ProxyFactoryComponent(target = SampleService(), interceptors
>>> "<Wrapped>You sent me 'something'</Wrapped>"
Visit the website at http://springpython.webfactional.com, and read
about AOP, along with the other features provided by this library.
More information about the Python-list