[Zope] Override a method of an instance in the ZODB?

Alec Mitchell apm13 at columbia.edu
Fri May 28 22:50:34 EDT 2004


On Friday 28 May 2004 11:52 am, Dieter Maurer wrote:
> Alec Mitchell wrote at 2004-5-27 13:11 -0700:
> >I'm wondering if it is possible to override a method on a single instance
> > of an object in the ZODB.  My suspicion is no, but it doesn't hurt to
> > ask.
>
> You can but it is a bit tricky because Python performs
> method wrapping only for class attributes.
>
> Thus, you need to do your own wrapping. Something like this:
>
>       from Acquisition import Explicit
>       class _MethodWrapper(Explicit):
>         def __init__(self, f): self.__f = f
> 	def __call__(self, *args, **kw):
> 	  return self.__f(self.aq_parent, *args, **kw)
>
>       instance.f = _MethodWrapper(your_funcion)
>
>
> Note, that your "your_function" must be pickleable and unpickleable.
> This means, it must be defined in the module (global) namespace.

Great! That's exactly what I was looking for.

Thanks,
Alec Mitchell



More information about the Zope mailing list