Re: [Pyobjc-dev] aspect/advice -- wrapping methods
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2006-04-16 12:35:39
|
This one actually works: def addTracing(method): origFunction = method.definingClass.instanceMethodForSelector_ (method) def wrapper(self, *args): print "HERE!",self, args return origFunction(self, *args) setattr(method.definingClass, method.__name__.replace(':', '_'), wrapper) Ronald On 16-apr-2006, at 14:17, ytrewq1 wrote: > Thanks for the suggestion. I tried it out and encountered a few > issues so > I tried the following modified version, but now I encounter > application > crashing: > > def addTracing(method): > cls = method.definingClass > nm = method.selector.replace(':', '_') > origMethod = cls.instanceMethodForSelector_(nm) > def wrapper(self, *args): > print self, args > return origMethod(self, *args) > setattr(cls, method.__name__, wrapper) > > In one crash, I noticed the following sort of output in Console.app: > > An uncaught exception was raised > exceptions.RuntimeError: maximum recursion depth exceeded > *** Uncaught exception: <OC_PythonException> exceptions.RuntimeError: > maximum recursion depth exceeded > > Does it look like I made inappropriate modifications? > > On 4/16/06, Ronald Oussoren <ron...@ma...> wrote: >> >> Something like this should do it: >> >> <warn>This code was typed in the browser</warn> >> >> def addTracing(method): >> cls = method.im_class >> nm = method.sel_selector >> >> origMethod = cls.instanceMethodForSelector_(nm) >> >> def wrapper(self, *args): >> print self, args >> origMethod(self, *args) >> >> setattr(cls, method.__name__, wrapper) >> >> addTracing(NSObject.init) >> >> Ronald >> |