Yes, I can give you a diagram, but my Python is a little rusty, and I'm too busy to explain in detail.
Basically, you need to put the proxy in a method that will call the original, for example:
class fred(object): def blog(self): print "We Blog" class methCallLogger(object): def __init__(self, meth): self.meth = meth def __call__(self, code=None): self.meth()
This https://stackoverflow.com/a/4646266/ about the callee can help you understand the above.
More details:
Although the answer was accepted, due to an interesting discussion with Glenn and some free time, I wanted to increase my answer:
# helper class defined elsewhere class methCallLogger(object): def __init__(self, meth): self.meth = meth self.was_called = False def __call__(self, code=None): self.meth() self.was_called = True #example class fred(object): def blog(self): print "We Blog" f = fred() g = fred() f.blog = methCallLogger(f.blog) g.blog = methCallLogger(g.blog) f.blog() assert(f.blog.was_called) assert(not g.blog.was_called)
Andy Dent Sep 30 '10 at 10:46 2010-09-30 10:46
source share