[ZPatterns] what I'm doing wrong? PlugIns bug?

Juan David Ibáñez Palomar [email protected]
Thu, 25 Oct 2001 18:27:06 +0200


Antonio Beamud Montero wrote:

> On Thu, 2001-10-25 at 15:02, Steve Alexander wrote:
> 
>>Antonio Beamud Montero wrote:
>>
>>
>>>Eureka!!! Al works ok... yepppa, and now my question, why I need to wrap
>>>again this objects? 
>>>
>>
>>You shouldn't store wrapped objects. I think the ZODB will strip them 
>>for you if you do try to store them.
>>
> 
> Then, how can I store references to another objects? Perhaps I have a
> bad design of my systems...
> 


Perhaps. Try this:


from ExtensionClass import Base
from Acquisition import Implicit

class A(Base):
     def __init__(self, ob):
         self.map = {'ob': ob}
         self.ob = ob


class B(Base, Implicit):
     pass


a = A(B())

print a.ob is a.map['ob']


When this code is executed it returns 0, "a.ob" and "a.map['ob']"
are different, the first one is an acqusition wrapper, the last
one is not. The __of__ method of the B instance (defined in
Implicit) is only called when the object is accesed as a subobject
of "a", then it returns the acq. wrapper.

That is, you have two options:

  - Access always to your instances through "self":

      def list(self):
          return [ getattr(self, x) for x in self._cons.keys() ]

    This solution only works if you store your objects in "_cons"
    and as attributes of "self".

  - Explicitly wrapp them (but don't store the wrapped object, as
    Steve explained):

      def list(self):
          return [ x.__of__(self) for x in self._cons.values() ]


Ummhh.. it seems the problem has nothing to do with PlugIns, so it's
becoming offtopic for this mailing list.


jdavid