[Zope] dtml2python (sorry, forgot the subject)

Dieter Maurer dieter@handshake.de
Tue, 27 May 2003 21:07:10 +0200


Dieter Fischer wrote at 2003-5-26 23:51 +0200:
 > I didn't find the equivalent commands in python (script) for this two dmtl
 > commands:
 > 
 > <dtml-try>
 >    ...
 > <dtml-except DatabaseError>
 >    <dtml-if "error_type == 'IntegrityError'">
 >       ...
 >    </dtml-if>
 > <dtml-else>
 >       ...
 > </dtml-try>
 > 
 > ---
 > 
 > try:
 >    ...
 > except DatabaseError:
 >    if error_type == 'IntegrityError':
 >       ...
 >    else:
 >       ...
 > 
 > doesn't work. Have I to import something to access the variables, or what am
 > I missing?

Exception handling is nasty in Python Scripts...

You must provide the necessary security declarations (read
"PythonScripts --> README") and then import the exceptions
you want to catch.

The "except" clause has the form:

  except [ExceptionDesignator [, name]]:

When you add the ",name", then "name" is bound to the exception
value and you can in principle analyse it.
But, usually, the necessary security declarations are missing.

The easiest solution would be to move exception handling into an ExternalMethod
(or use "XXXPythonScripts", the PythonScript without security
restrictions).

If this is no option for you, giving "Exception" the necessary
security declaration through monkey patching might be partial solution.


Dieter