[Zope] overloading getattr on a product

Chris Withers chrisw@nipltd.com
Fri, 16 Aug 2002 10:49:23 +0100


Christopher N. Deckard wrote:
> I'm writing a product which stores the equivalent
> of Folder properties in XML.  Now I want to be
> able to catalog objects of this type, but looking
> at how that's done by the ZCatalog shows that
> getattr(object, index) is called for all indexes.  

Hmmm, maybe it tries a object[index] if that fails?

> My product is subclassed from ParsedXML and uses
> the DOM to go through the tree and find my
> "properties".  What seems to be happening is that
> when I define a new __getattr__, implicit getattr
> calls are made to the DOM object and it ends up
> calling my newly defined getattr method.  This
> sort of send it into a recursive neverending loop.

You have a self somewhere in you __getattr__ which you don't meant to be there ;-)

In general, overloading __getattr__ in the presence of acquisition is akin to 
putting a fluffy kitten on a railway track when you don't know what times the 
trains run...

cheers,

Chris