Wrap and intercept function calls

Dan Yamins dyamins at gmail.com
Wed Feb 17 01:29:55 CET 2010


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
            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?

-------------- 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