After a closer look, it would seem that nearly all of the 'Unauthorized' string exceptions have been replaced with a bonified exception object. So that is probably why it doesn't work. You could try importing this class in the python script using:: from zExeptions import Unauthorized and catch exceptions of this class. I have a feeling this import is not possible fom a python script however (though it probably should be). So that leaves you little choice but to either use a bare except, or write the code in an external method or other trusted code module. -Casey ----- Original Message ----- From: "John K. Hohm" <jhohm@acm.org> To: "Casey Duncan" <casey@zope.com> Cc: "Dieter Maurer" <dieter@handshake.de>; <zope@zope.org> Sent: Saturday, October 26, 2002 12:40 PM Subject: Re: [Zope] using getProperty and catching Unauthorized
Quoting Casey Duncan <casey@zope.com>:
Yes, but as of right now, Python strings that do not contain spaces are interned as the same object. So as long as the name does not have a space in it, it should work.
Thanks all, for the responses. Perhaps it should work, but it doesn't. I get the Unauthorized exception in my browser even though I'm doing this:
try: menu_order = sibling.getProperty('menu_order', None) except 'Unauthorized': continue
I somehow got the impression from reading the Python manual that raising an exception with a string that is the name of a class will raise the class instead, so I tried doing this:
from AccessControl import Unauthorized #... try: menu_order = sibling.getProperty('menu_order', None) except Unauthorized: continue
But then I get this incredibly ironic error in the browser: Error Type: ImportError Error Value: import of "Unauthorized" from "AccessControl" is unauthorized. You are not allowed to access Unauthorized in this context
So apparently I'm allowed to call things that throw Unauthorized, but I'm not allowed to import Unauthorized in order to catch it? Harsh. Is there some other way of going about this? Perhaps some function that simulates the access control check that happens inside the acquisition wrapper, and returns a booleanish result?
That said, string exceptions suck rocks. But string exceptions with spaces suck gravel ;^)
-Casey
On Fri, 25 Oct 2002 21:37:53 +0200 Dieter Maurer <dieter@handshake.de> wrote:
Casey Duncan writes:
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.. It may not work, because Python uses "is" to check against string exceptions and not "==".
Dieter