Hi, Can anyone point me towards documentation / howtos / information on handling exceptions in python scripts (scripts not 'external methods'). I have a core set of page templates that determine their content based on the traverse_subpath. Due to the inability of some browsers to understand the base tag, I have just re-implemented this logic python. However, I cannot handle the exceptions in python. Using page templates I can handle exceptions, but not using a python script. I want such logic as: pt = container.x return pt() except AccessControl.unauthorized.Unauthorized: return container.acl_users.redirectToLogin(request) except ... NotFound : .... except: ... But access to the python exception functionality is not available. Furthermore, access to the sys variables for exceptions are also not available. When I use page templates I have a variable called '_', and can do some nasty work .... error = _['error'] if str(error.type) == "AccessControl.unauthorized.Unauthorized": return container.acl_users.redirectToLogin(request) However, there is no _ in the python script. So I need to have scripts calling page templates calling scripts so that I can get the exception information. This is the sort of coding that makes Visual Basic look clean! This problem is so fundamental that I am sure there is plenty of documentation in the zope site. Unfortunately, I cannot find it. If anyone can point me to the HowTos or other documentation on this problem, I would be grateful. Thanks in advance, Kevin Gill PS - Remember the question is about python scripts. Please do not send me messages about external methods.
On Wed, Dec 18, 2002 at 09:54:26PM +0000, Kevin Gill wrote:
I want such logic as:
pt = container.x return pt() except AccessControl.unauthorized.Unauthorized:
You're missing the "try" keyword: try: do_something() except SomeErrorClass: do_something_else()
But access to the python exception functionality is not available.
Yes it is.
Furthermore, access to the sys variables for exceptions are also not available.
The what variables?
When I use page templates I have a variable called '_', and can do some nasty work ....
error = _['error'] if str(error.type) == "AccessControl.unauthorized.Unauthorized": return container.acl_users.redirectToLogin(request)
However, there is no _ in the python script.
I'm very confused. Are you talking about the DTML namespace variable? What do you do with a _ variable in Page Templates? -- Paul Winkler http://www.slinkp.com "Welcome to Muppet Labs, where the future is made - today!"
Kevin Gill writes:
Can anyone point me towards documentation / howtos / information on handling exceptions in python scripts (scripts not 'external methods'). Apparently, someone forget that exception handling may be interesting in Python Scripts.
He forgot to provide the necessary security declarations. When you can add/change products, you can provide the missing security declarations. See the "Readme" tab of the "PythonScripts" product. Once, you did this, you can handle exceptions in the normal way. The standard Python exceptions can be imported from the "exceptions" module. Dieter
participants (3)
-
Dieter Maurer -
Kevin Gill -
Paul Winkler