Helping ordinary people create extraordinary websites!
HOME TUTORIALS SCRIPTS WEB HOSTING BLOG FORUM
Get Our Newsletter
Email:

Extending Python and Zope in C

By Michael Roberts
2004-12-04


Zope scripts: Cliff Notes version

Zope scripts are a new feature with Python 2.3, and they are intended to supplant External Methods. They can do anything External Methods can do, but they're better integrated with the security and management system, they offer more flexibility in integration, and they also have a great deal more access to all the Zope functionality exposed in the Zope API.

A script is basically just a short Python program. It can define classes or functions, but doesn't have to. It's installed as an object in a Zope folder, and can then be called as a DTML variable or call (like an External Method) or "from the Web", which is a Zopism meaning that it will be invoked as a page. This implies, of course, that a script can generate the response to a forms submission, just like a CGI program but without the CGI overhead. A nifty feature indeed. In addition, the script has access to the object it's been invoked on or from (via the "context" object), the folder that object is in (via the "container" object), and a few other odds and ends of information. For a great deal more information about scripts, see the chapter "Advanced Zope Scripting" in The Zope Book (see Resources).

You might make the mistake of thinking that you can simply import foo and use foo.bar directly from a script (I know I did). However, this isn't the case. Due to security restrictions, only Products can be imported, not arbitrary modules. As a general policy, the Zope designers have the idea that access to the file system is required for arbitrary scripting, and since script objects are managed from the Web using the Zope management interface, they're not fully trusted. So instead of showing you an example script, I'm just going to cut to the chase and talk about Products and base classes.

Tutorial Pages:
» The Best of Both Worlds
» Extending Python for Fun and Profit
» Writing the Code
» Building the Extension
» Taking it to Zope
» Creating an External Method
» Zope scripts: Cliff Notes version
» Going all out With a Product
» Where to go From Here
» Resources


First published by IBM DeveloperWorks


 | Bookmark
Related Tutorials:
» Python and Java - A Side by Side Comparison
» Learn Python in 10 Minutes
» Python 201 - (Slightly) Advanced Python Topics
» Python 101 - Introduction to Python
» Google Sitemaps
» Python 101