[ZPT] Unicode and 8-bit string migration fix

Barry Warsaw barry at python.org
Fri Oct 17 09:35:29 EDT 2003


On Fri, 2003-10-17 at 01:29, Stuart Bishop wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Hi.
> 
> Starting with Zope 2.6, Zope became capable of publishing Unicode. 
> However,
> Page Templates which mixed Unicode and 8-bit encoded strings would raise
> a Unicode exception:
> 
> 	<p tal:content="python:u'My 2\N{CENT SIGN}'" />
>      <p tal:content="python:u'My 2\N{CENT SIGN}'.encode('latin1')" />

I think this is probably the basic problem.  Why are you encoding this
unicode string here in your zpt?  I'm pretty sure everything coming out
of tal should just be unicode strings, and components such as the
publisher should encode for the output stream as appropriate or needed. 
That retains the separation of concerns, and helps to maintain developer
sanity.

I think the basic philosophy ought to be: convert to and from unicode at
the farthest boundaries you can get away with, treat everything
internally as unicode always, and never mix unicode and 8-bit strings.

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://lists.zope.org/pipermail/zpt/attachments/20031017/561d6621/attachment.bin


More information about the ZPT mailing list