[ZPT] Unicode error in PageTemplates/XML

Stuart Bishop stuart.b at commonground.com.au
Mon Dec 15 21:23:28 EST 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On 16/12/2003, at 3:06 AM, Santi Camps wrote:

> give_me_content (Python Script):
> return 'maó'

You should use a Unicode string here:
	return u'ma\N{LATIN SMALL LETTER O WITH ACUTE}'

Otherwise, I'm not sure what character set that string will
actually end up in (in a default Zope, probably ISO-8859-1).

Your xml would then look like:

<?xml version="1.0" encoding="ISO-8859-15"?>
<doc xmlns:tal="http://xml.zope.org/namespaces/tal">

     <tal:b condition="python:request.RESPONSE.setHeader(
		'Content-Type','text/xml; charset=ISO-8859-15')" />

   <body tal:content="here/give_me_content" />
</doc>


The tal:b bit sets the content type header with an explicit charset,
which Zope uses to encode the result. Zope does not (yet) pick
up the 'encoding=' element of the XML header.

> not in range(128)".  My surprise is that test2_xml works fine, so it
> seems to be a problem of TALES.  I've tried to encode the result using
> UTF-8, but doesn't works.  It seems that only 7bit strings are allowed.
> I've also tried to debug PageTemplate.py code, but I'm not able to find
> where the problem is.  Perhaps this is a problem of standard StringIO
> module, but then, why it works in HTML?

You get those error messages if you mix Unicode strings with encoded
strings. On the page template's edit screen, if you set the content-type
of the page template to text/xml stricter XML validation kicks in, which
might be triggering it. As Page Templates is a fully Unicode aware
product, this could be considered a feature (and your test_html working 
a
bug).

> Anybody knows something about this?  I'm really interested into 
> generate
> XML using TALES, but I need to be able to generate LATIN encodings.

Use Unicode strings instead of latin encoded strings. If your data 
source
is latin encoded, you might need to do "unicode(data,'iso-8859-15')" to
convert your data to a Unicode.

- --  
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (Darwin)

iD8DBQE/3myuAfqZj7rGN0oRAkdVAJwMTf6qL9kM/FDPRasS5yJGayQFPQCfUnIa
M10vsWvKNuSeebXw/W8LOio=
=Lu8X
-----END PGP SIGNATURE-----




More information about the ZPT mailing list