classes in external methods
Since Zope's Python Scripts will not allow me to import the csv module, I wrote my own little class within an External Method. My class opens a CSV file and returns a dictionary representation of each line, one at a time. Now Zope pops up an authentication dialog when I try to call my External Method. Is there some way around this? Can someone also explain why Zope does this? I thought an External Methods was a failsafe way to write unrestricted Zope code without going all out and writing a product (which just doesn't make sense in this instance). Nathaniel
nwingfield@dixon-hughes.com wrote:
Since Zope's Python Scripts will not allow me to import the csv module, I wrote my own little class within an External Method. My class opens a CSV file and returns a dictionary representation of each line, one at a time. Now Zope pops up an authentication dialog when I try to call my External Method. Is there some way around this? Can someone also explain why Zope does this? I thought an External Methods was a failsafe way to write unrestricted Zope code without going all out and writing a product (which just doesn't make sense in this instance). Nathaniel
It is. But the object you return is probably not a simple Python data type. As far as I remember the csv module returns some kind of iterator, (a Reader object?) not just a list of dictionaries. Such a class can not be accessed by dtml/zpt. It is protected by the security machinery. This means that you either need to set:: obj.__allow_access_to_unprotected_subobjects__=1 On the reader object that is returned. Or you could convert it to a real list of dictionaries and return that. Which is the most correct way to do it. Such simple types are not protected by Zope. regards Max M -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
nwingfield@dixon-hughes.com wrote:
Since Zope's Python Scripts will not allow me to import the csv module, I wrote my own little class within an External Method.
Eh? I'd create some security declarations for the csv module in an empty product with a __init__.py, have a look in: /lib/python/Products/PythonScript/module_security_examples.py ...for examples. cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
participants (3)
-
Chris Withers -
Max M -
nwingfield@dixon-hughes.com