Wrap and intercept function calls

Dan Yamins dyamins at gmail.com
Tue Feb 16 19:29:55 EST 2010


Hi:

I'm wondering what the best way to wrap and modify function calls is.
Essentially what I want to achieve is to have a function like this:

def Wrap(frame,event,arg):
     if event == 'call':
        result = PerformCheck(GetArgumentsFromFrame(frame))
        if Condition(result):
            return result
        else:
            return [normal function call]

called whenever a "call" event is about to occur.

When I say "return result" I mean:  return that data object instead of what
the function would have returned, and prevent execution of the function.


Is there any way to do this using sys.settrace?  Or perhaps something from
the bdb or pbd module?

Thanks!
Dan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100216/2f7c539e/attachment.html>


More information about the Python-list mailing list