[ZPT] Making ZPT usuable outside Zope

Dieter Maurer dieter at handshake.de
Sun Aug 22 13:06:41 EDT 2004


Richard Jones wrote at 2004-8-22 17:45 +1000:
> ...
>> >>   2. implemented ustr as str (removes import from DocumentTemplate)
>>
>> Not sure, what "ustr" is -- but probably not "str"...
>
>See DocumentTemplate/ustr.py
>
>"ustr = str" works for my purposes.

"str" can fail for unicode values (it will when the
unicode value contains characters not representable
in Python's default encoding which defaults to US-ASCII).
"ustr" works around this problem.

Thus, the change may not be good when PageTemplates are
used in a unicode enabled environment.

> ...
>> >>   2. removed use of ExtensionClass
>> >>   3. removed use of ComputedAttribute
>>
>> not sure whether these are essential...
>
>As I mentioned in my message to Chris, which he quoted, I'm not sure what the 
>repurcussions might be of:
>
>1. removing the Base base class from PageTemplate, and

"ExtensionClass.Base" is a very usefull base class.

It is a prerequisite that "ExtensionClass" related extensions
like "ComputedAttribute" and Zope's security machinery work.

For PageTemplates in the Zope context, this base class
is vital but can be added in "ZopePageTemplate", "FSPageTemplates"
and the Zope version of "PageTemplateFile".

>2. changing the macros attribute implementation from a ComputedAttribute to
>   a __getattr__ one.

It is very easy to implement "__getattr__" in a way leading to
spurious infinite loops. In a multi-threaded application (such
as Zope), such infinite loops may end in a "C" runtime stack
overflow. They are not easy to diagnose, unless one is familiar
with "C" level debugging.
The danger drastically increases in a Acquisition enabled
environment. Your modified PageTemplates may enter this world
through subclassing (e.g. "ZopePageTemplates").

"ComputedAttribute" is much more reliable (in this sense).

But, of course, one can implement "__getattr__" without the
danger of infinite loops.

>> >> Expressions.py
>> >>   1. removed all Zope-specific code (doesn't even try to import that
>> >>      stuff now)
>>
>> If they work without -- maybe...
>
>Again, it was easier to just remove the code that move around all the imports. 
Shane introduced traceback supplements implemented in
the "zExceptions" package. Such tracehack supplements are
a *BIG* win for problem analysis (together with the "ExceptionFormatter"
also defined in this package).

Maybe, we should continue to allow
"PageTemplates" (and "TAL/TALES") to use "zExceptions",
even this has a "z" in its name ;-)

> ...
>> >>   3. removed blocking of leading-underscore URL components
>>
>> Surely, this should stay inside Zope...
>
>Yep. Not sure how this would be handled...

By a method performing the check that can be redefined in
Zope specific incarnations.

-- 
Dieter


More information about the ZPT mailing list