Re: [Pyobjc-dev] aspect/advice -- wrapping methods
Brought to you by:
ronaldoussoren
|
From: ytrewq1 <yt...@gm...> - 2006-04-16 13:07:32
|
I verified that that works for a few cases here. Thank you very much!
On 4/16/06, Ronald Oussoren <ron...@ma...> wrote:
> This one actually works:
>
> def addTracing(method):
> origFunction =3D 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 =3D method.definingClass
> > nm =3D method.selector.replace(':', '_')
> > origMethod =3D 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 =3D method.im_class
> >> nm =3D method.sel_selector
> >>
> >> origMethod =3D cls.instanceMethodForSelector_(nm)
> >>
> >> def wrapper(self, *args):
> >> print self, args
> >> origMethod(self, *args)
> >>
> >> setattr(cls, method.__name__, wrapper)
> >>
> >> addTracing(NSObject.init)
> >>
> >> Ronald
> >>
>
>
|