[ZPT] Using PTFiles in Python Products

Michael R. Bernstein webmaven@lvcm.com
13 Jul 2002 09:51:46 -0700


On Sat, 2002-07-13 at 04:24, Chris Withers wrote:
> "Michael R. Bernstein" wrote:
> > 
> >             # retreive contained object if it exists
> >             print "object is not int-like " + name
> >             if name in self.objectIds():
> >                 print "returning contained object " + name
> >                 return getattr(self, name)
> >             # return attribute (if no matching contained object is
> >             # found).
> >             elif hasattr(self, name):
> >                 print "returning object attribute " + name
> >                 return getattr(self, name)
> 
> These two return statements don't do any acquisition wrapping, maybe they
> should?
> Probably not but it might be worth a try...

Let's see...

The contained objects are stored with an acquisition wrapper, and the
same goes for acquired objects (returned by getattr). The only case I
can think of that wouldn't be covered would be getattr returning a
simple attribute (not a persistent object) such as a title. I don't
think that wrapping those in an acquisition wrapper is appropriate
either, But I could be wrong.

In any case, as I posted in reply to Dieter, once I fixed the stupid
mistake I made with defining the PTFile, my acquisition problems went
away.

> >             else:
> >                 # return object stored in BTree
> >                 print "returning object in BTree " + name
> >                 return self.Postings[name].__of__(self)
> >         print "returning weblog object " + name
> >         return self
> 
> what case does this 'return self' handle?

As I understand it (because I modified this code from Karl's), this
handles the case of there not being any subobjects to traverse, ie, the
object is itself being accessed.

Cheers,

Michael.