Chris Withers wrote:
> Chris Withers wrote:
> > Steve Alexander wrote:
> > > > Do you know if objects in PARENTS are acquisition wrapped?
> > > I'm pretty sure that they are.
> >
> > They are indeed, in fact, pretty much everything is :(
> > The only way to check if o is in PARENTS appears to be:
> > if o.aq_base in map (lambda o : o.aq_base,PARENTS):
> Hmm, is there anyway the Acquisition ExtensionClass(right thing? I'm not
> too hot here ;-) could be altered such that, if r1 and r2 are two
> different acquisition wrappers for the same object that:
> r1 == r2 and r1 in [r2,x,y]
> would return true?

Yes. I think that this would be a great idea.

Note that if r1 implements __cmp__, then it is called.
This means that you could implement the proposed behavior now

  def __cmp__(self, o):
     return cmp(
        id(getattr(self, 'aq_base', self)), 
        id(getattr(o, 'aq_base', self))

It also means that (with the proposed change) that '=='
will only be equivalent to an identity comparison if
an object doesn't define comparison.  In most cases, however,
this shouldn't be a problem.

> It might be best to leave (r1 is r2) returning false as it does now so
> that you can actually tell if things aren't what you expected ;-)

Good, because there's no hook to override 'is'.

> PS: This question is still worrying me :(
> > 2. Is there any case where a Zope object isn't going to have a .aq_base
> >    attribute?

Sure. There is no guarentee that all objects are wrapped.

A common idiot for dealing with this is getattr(o, 'aq_base', o).
So your example above would become:

  if getattr(o, 'aq_base', o) in map (
     lambda o : getattr(o, 'aq_base', o),

I've considered implementing the aquisition attributes in
the Implicit and and explict base classes, which would probably
be a good idea.


Jim Fulton           mailto:[EMAIL PROTECTED]   Python Powered!        
Technical Director   (888) 344-4332    
Digital Creations    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for

Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to