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

Dieter Maurer dieter at handshake.de
Fri May 28 14:52:49 EDT 2004


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.

-- 
Dieter



More information about the Zope mailing list