[Zope] restrictedTraverse without acquisition

Paul Winkler pw_lists at slinkp.com
Tue Jul 13 14:40:01 EDT 2004


On Tue, Jul 13, 2004 at 10:50:59AM -0700, R Karthick wrote:
> 
> hi!!
> 
> thank you for you reply.
> 
> Yeah it seems to be a good solution. but can't i just
> switch off acquisition in restrictedTraverse, when i
> need to?

restrictedTraverse has no such feature.

You could also item access rather than attribute access.
This does not use acquisition. e.g.:

try:
    context.wg['projects']['abc']
    ...

> > 
> > How about something like: (warning - untested)
> > 
> > foo = context.restrictedTraverse("wg/projects")
> > found = 0
> > for i in foo.objectItems():
> >    if str(i[0]) == 'abc':
> >       found = 1

That works, as long as you don't mind wasting the cycles to 
look at every object in foo :-)
but even in that case I would use objectIds() instead of objectItems().

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list