Re: [Zope] handling exceptions for external methods
On Sat, Jul 07, 2007 at 08:11:29AM +0200, Andreas Jung wrote: > >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. > okay, I was thinking strictly in terms of using an external method in a tal statment. All the examples I've seen in the zope book all have external methods return html or xml as data that is sent back to the browser. I never though of having an external method return a standard python object back to a script and then have the script do something with the object. It would be really nice if there were more examples of using external methods -- my concept of how to use them gets limited by the examples that I see. So, if there are more examples or use cases of external methods, I'd appreciate a pointer to them. Thanks. > >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 > -- David Bear phone: 602-496-0424 fax:602-496-0955 College of Public Programs/ASU University Center Rm 622 411 N Central Phoenix, AZ 85007-0685 "Beware the IP portfolio, everyone will be suspect of trespassing" ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] handling exceptions for external methods
(Fri, Jul 06, 2007 at 02:55:47PM -0700) David Bear wrote/schrieb/egrapse: > 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 > > 2 external methods have access to a larger namespace and therefor more ... snip ... You forgot this one: 0 external methods are just a hack, they are to be used only in exceptional cases. Learn how to make a filesystem based python product instead and waste as little time as possible on external methods. Hope this helps! Regards, Sascha ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] handling exceptions for external methods
Jonathan wrote at 2007-7-7 08:55 -0400: > ... >Just one caveat: you cannot define a class within an external method and >then return an instance of that class (the routine that invoked the external >method will not have any reference to the instance's class). You can. You must, however, be aware that such classes are not picklable. The source of "External Method"s are read in ("execfile"d) and classes defined therein appear as if defined in the module "__main__". This confused the pickling mechanis as "__main__" is unable to recreate these classes. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] handling exceptions for external methods
David Bear wrote at 2007-7-6 14:55 -0700: > ... >5 external methods do not have access to stdin/stdout They have. However, "stdin/stdout/stderr" have not much worth in "server mode". "server mode" means that there is no "terminal" where this IO comes from is directed to. You can change Zope's startup script and then redirect the standard IO channels (stdin/out/err) to files (we do that occasionally, to catch messages written by external components). Or, you can start Zope in the "foreground". In both cases, your "External Method" can use "stdout/stderr" (use of "stdin" is very doubtful) to provide messages to use. -- Dieter ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] handling exceptions for external methods
- Original Message - From: "Andreas Jung" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "zope" Sent: Saturday, July 07, 2007 2:11 AM Subject: Re: [Zope] handling exceptions for external methods 6 external methods must return only strings, Nonsense. External methods can return anything. Just one caveat: you cannot define a class within an external method and then return an instance of that class (the routine that invoked the external method will not have any reference to the instance's class). If you want to create your own object classes then put the class definitions in a Zope Product. You can then access that class from within an external method and then return instances of the class to the routine that called the external method (the calling routine will be able to reference the class because of the Zope Product). Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] handling exceptions for external methods
--On 6. Juli 2007 14:55:47 -0700 David Bear <[EMAIL PROTECTED]> 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 pgpLrcKitsJP7.pgp Description: PGP signature ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Re: [Zope] handling exceptions for external methods
- Original Message - From: "David Bear" <[EMAIL PROTECTED]> To: "zope" Sent: Friday, July 06, 2007 5:55 PM Subject: [Zope] handling exceptions for external methods 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) 3 external methods inherit the same namespace available to scripts running inside zope when you define your external method routine: def xxx(self, ) you gain access to zope namespace via self (eg. self.REQUEST) 6 external methods must return only strings, but they may be unicode string as long as they are valid xml string data No. External methods can return any python type you like (lists, tuples, dictionaries, etc). 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? Look up try/except in a python lib doc. hth Jonathan ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] handling exceptions for external methods
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 2 external methods have access to a larger namespace and therefor more functionality 3 external methods inherit the same namespace available to scripts running inside zope 4 external methods are not launched as forked or spawned child processes 5 external methods do not have access to stdin/stdout 6 external methods must return only strings, but they may be unicode string as long as they are valid xml string data 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? -- David Bear phone: 602-496-0424 fax:602-496-0955 College of Public Programs/ASU University Center Rm 622 411 N Central Phoenix, AZ 85007-0685 "Beware the IP portfolio, everyone will be suspect of trespassing" ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )