--On 6. Juli 2007 14:55:47 -0700 David Bear <David.Bear@asu.edu> wrote:
I've begun using external methods and am trying to better understand the context they run and and how to handle exceptions. I have concluded the following (and I don't recall reading some of these in any documentation) (please correct me if I'm wrong)
1 external methods run in the same interpreter as zope
right
2 external methods have access to a larger namespace and therefor more functionality
they have access to the *full* Python functionality
3 external methods inherit the same namespace available to scripts running inside zope
inherit? Using 'self' as first parameter give you access to the current object (for acquisition).
4 external methods are not launched as forked or spawned child processes
right
5 external methods do not have access to stdin/stdout
There is no usecase for accessing stdin from external methods and you might to use stdout only for debugging purposes only.
6 external methods must return only strings,
Nonsense. External methods can return anything.
but they may be unicode string as long as they are valid xml string data
Nonsense. There is no contract in Zope telling some method to return XML at all.
Something that I don't understand is how to handle an exception. For example, if I have an external method that appends data to the end of a file, if there is an IOException how to I capture it and send a message back to zope with something informative?
You must raise an exception if your failure is supposed to perform a ZODB abort operation. Otherwise catch the exception and return some friendly error message back. -aj