[Zope] using getProperty and catching Unauthorized

Casey Duncan casey@zope.com
Fri, 25 Oct 2002 15:25:54 -0400


So long as the string doesn't contain a space, then it is always interned by Python:

>>> a = 'Not Found'
>>> b = 'Not Found'
>>> a is b
0
>>> a = 'Unauthorized'
>>> b = 'Unauthorized'
>>> a is b
1

So it works if the string exception doesn't contain a space, otherwise you're hosed ;^)

-Casey

On Fri, 25 Oct 2002 20:46:32 +0200
Florent Guillaume <fg@nuxeo.com> wrote:

> This kind of thing only works if the 'Unauthorized' string is always
> interned, which I'm not sure is guaranteed...
> 
> I know I've had things like that *not* work in python scripts.
> 
> Florent
> 
> In article <20021025100215.65bc8b3e.casey@zope.com> you write:
> > I think the following should do what you want:
> > 
> > for foo in bar.objectvalues()
> >     try:
> >         mo = foo.getProperty('menu_order', None)
> >     except 'Unauthorized':
> >         continue
> >     ..do stuff..
>