[Zope] Exceptions in Python Script

Kevin Gill kevin@movieextras.ie
Wed, 18 Dec 2002 21:54:26 +0000


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.