PythonScript getting at various Python libraries
I'd like to get access to a bunch of libraries that Python has, like "re" and "time" and "xml" and "md5", etc. What is the standard way that I can go about doing this?
I'd like to get access to a bunch of libraries that Python has, like "re" and "time" and "xml" and "md5", etc. What is the standard way that I can
go
about doing this?
Use External (Python) Methods for calling anything that falls under the Python Script restrictions. Then call the External Method from Python Scripts if still applicable. hth Rik
I'd like to get access to a bunch of libraries that Python has, like "re" and "time" and "xml" and "md5", etc. What is the standard way that I can
go
about doing this?
The problem with putting everything in an External Method is of course security. Maybe it would be a good idea if there exists a repository of ExternalModuleImports somewhere at zope.org. These would be ExternalMethods (or something similar) which import a module, but remove all defs with security implications (like file access). That way, security patches are more easily distributed to those concerned. Daniel
I'd like to get access to a bunch of libraries that Python has, like "re" and "time" and "xml" and "md5", etc. What is the standard way that I can go about doing this?
Use External (Python) Methods for calling anything that falls under the Python Script restrictions. Then call the External Method from Python Scripts if still applicable.
Alright. I now have an external method that returns me a reference to the md5 module: def hello(self): """ Whatever """ import md5 return md5 I can, in my PythonScript, do a x = context.hello() and get back a reference to the md5 module, but when I then do a m = x.new() which is supposed to get me a new md5 instance, and I hit that PythonScript, Zope pops up an authentication box and refuses to let me continue. If I call the external method directly through the browser, I get a string saying that it is an md5 module. So what am I doing wrong now?
Gerald Gutierrez wrote:
I'd like to get access to a bunch of libraries that Python has, like "re" and "time" and "xml" and "md5", etc. What is the standard way that I can go about doing this?
Brian Lloyd posted about this recently on zope-dev: http://zope.nipltd.com/public/lists/dev-archive.nsf/ByKey/D8B8A71284D49682 I think there's plans for a Utility to do this kindof thing that might ship in Zope 2.3.1. Maybe Brian can shed some light? cheers, Chris
Brian Lloyd posted about this recently on zope-dev: http://zope.nipltd.com/public/lists/dev-archive.nsf/ByKey/D8B8A71284D49682
I think there's plans for a Utility to do this kindof thing that might ship in Zope 2.3.1.
Maybe Brian can shed some light?
Here is the contents of the PythonScripts README going out in 2.3.1, which describes how to make extra modules available. Note that the Utility module is new for 2.3.1, so you'll have to wait a few more days for 2.3.1 to be released or use CVS: Python Scripts The Python Scripts product provides support for restricted execution of Python scripts, exposing them as callable objects within the Zope environment. Providing access to extra modules Python script objects have a limited number of "safe" modules available to them by default. In the course of working with Zope, you will probably wish to make other modules available to script objects. The Utility.py module in the PythonScripts products provides a simple way to make modules available for use by script objects on a site-wide basis. Before making a module available to Python scripts, you should carefully consider the potential for abuse or misuse of the module, since all users with permission to create and edit Python scripts will be able to use any functions and classes defined in the module. In some cases, you may want to create a custom module that just imports a subset of names from another module and make that custom module available to reduce the risk of abuse. The easiest way to make modules available to Python scripts on your site is to create a new directory in your Products directory containing an "__init__.py" file. At Zope startup time, this "product" will be imported, and any module assertions you make in the __init__.py will take effect. Here's how to do it: o In your Products directory (either in lib/python of your Zope installation or in the root of your Zope install, depending on your deployment model), create a new directory with a name like "GlobalModules". o In the new directory, create a file named "__init__.py". o Edit the __init__.py file, and add calls to the 'allow_module' function (located in the Products.PythonScripts.Utility module), passing the names of modules to be enabled for use by scripts. For example: # Global module assertions for Python scripts from Products.PythonScripts.Utility import allow_module allow_module('base64') allow_module('re') allow_module('DateTime.DateTime') This example adds the modules 'base64', 're' and the 'DateTime' module in the 'DateTime' package for use by Python scripts. Note that for packages (dotted names), each module in the package path will become available to script objects. o Restart your Zope server. After restarting, the modules you enabled in your custom product will be available to Python scripts. Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
participants (5)
-
Brian Lloyd -
Chris Withers -
Daniel Dittmar -
Gerald Gutierrez -
Rik Hoekstra