[Zope3-dev] string agnostic page templates, again

Fred Drake fdrake at gmail.com
Tue Sep 7 12:23:59 EDT 2004


On Mon, 06 Sep 2004 14:46:08 +0200, Martijn Faassen <faassen at infrae.com> wrote:
> It seems the previous discussion about changing the ZPT engine so it
> also works with non-unicode text died down. This is still important for
> Five scenarios where the page templates need to interact with legacy
> Zope 2 content. Most Zope 2 content is not in unicode (though there are
> some exceptions such as Silva). In this case it is important that the
> page template engine can accept non-unicode input (*all* input being
> classic strings) without breaking.

Sorry for not getting back to this earlier; Jim and I talked about
this some last week, and left it on my plate to respond.  Well, here
goes...

One of my goals here is to not have two implementations of TAL in the
end.  I think we can accomodate this without a lot of pain.

The most important thing to note is that we really only care whether
something has been converted to a str or unicode value when writing it
to the output stream.  Since the TAL interpreter already uses a
subclass of StringIO, this can be handled by changing the write()
mehod of that object and removing the calls to str() / unicode() that
are the current cause for concern.  The modified write() method should
keep track of whether a unicode value is ever seen, and whether a
non-(str or unicode) value is ever seen.  If everything is a str or
unicode, it doesn't need to do anything special.  Otherwise, it needs
to apply str() or unicode() to anything that isn't one or the other to
perform the conversion (which will be determined by whether unicode
was ever seen), and then continue normally.

I think that keeps the whole thing properly unicode-agnostic, and
avoids having to deal with this issue all over the code; it becomes
isolated, and can be handled by overriding the StringIO factory on the
TALInterpreter if necessary.

Do you agree that this addresses your needs, Martijn?


  -Fred

-- 
Fred L. Drake, Jr.    <fdrake at gmail.com>
Zope Corporation


More information about the Zope3-dev mailing list