[ZPT] Making PageTemplates usable without Zope

Richard Jones rjones@ekit-inc.com
Mon, 19 Aug 2002 17:00:18 +1000


PageTemplates as they stand at present don't work without a Zope installation. 
That's due to two things:

1. It uses zLOG
2. It uses the ExtensionClass, Acquisition, ComputedAttribute and
   MultiMapping C modules

In my application, I don't want to have to force the users to compile C 
modules, and I don't want to have binary downloads. So, I did the following 
to a local version of ZPT:

1. wrote python ComputedAttribute and MultiMapping classes
2. removed use of Acquisition and ExtensionClass from:
   - PageTemplates/Expressions.py     (aq_base in render())
   - PageTemplates/PageTemplate.py    (Base base class)
   - ZTUtils/Batch.py                 (Base base class)
3. handle ImportError of ZTUtils/Tree.py in ZTUtils/__init__.py (does
   nothing if there is an error) ... since I can do without this
4. handle inability to import zLOG in TAL/XMLParser.py

Other than that, my simple test works:

>>> from PageTemplates.PageTemplate import PageTemplate
>>> pt = PageTemplate()
>>> pt.write('''<p tal:define="x options/x"
...      tal:content="python:x+1">???</p>''')
>>> print pt(x=1)
<p>2</p>

... so I'm fairly happy. The open question is whether this work belongs in the 
ZPT codebase, and in what form. I think most of it can be done with minimal 
impact in the ZPT codebase, by just handling import errors... The 
ComputedAttribute and MultiMapping modules are quite simple (obviously) .. 
though I'm not entirely sure I got ComputedAttribute right (hard to test - 
mostly it exists to shut the import error up ;). I wouldn't even think 
there'd be a huge speed difference between ZPT running with the C 
MultiMapping and the python one (it's really not that complex ;), but that's 
untested.


     Richard