[Zope] zpt encoding and content-type
tpassin at mitretek.org
Wed Oct 22 11:10:16 EDT 2003
> i use PageTemplateFile in my python product. now I'm
> wondering if there
> is some way to redefine the content-type and the encoding of the
> response object in the file
> ... it seems that PageTemplateFile
> always uses text/xml if an xml PI is on the top of the source
> file. It
> sniffs the content-type from the PI.
> what I basically want to do is, to define the encoding in the xml PI
> (e.g <?xml version="1.0" encoding="iso-8859-1"?>) so that I dont get
> unicode conversion errors (ascii out of range ...) when the
> file is read
> but this results in a text/xml content type
I don't have the answer for you, but "text/xml" is correct for xml
having any character encoding. Also as a technicality, the thing you are
talking about is not actually a PI, even though it looks like one.
Strictly speaking, it is the "XML Declaration", and does not (or should
not) get passed through to the application as a PI would.
So the answer lies in getting the actual encoding of the page and the
declared encoding to agree - by default the declared encoding is utf-8
or utf-16. The fact that your application gives you "ascii out of
range" errors indicates that it is assuming ascii encoding, which in
turn indicates that it is not correctly paying attention to the encoding
rules - otherwise it would be using utf-8 (and possibly finding
If the application is written in Python (and I think I recognize that
error message), then it is using ordinary Python strings instead of
unicode strings. So you seem to have two problems -
1) get the encoding declared correctly.
2) get the processing app to process the encoding correctly.
More information about the Zope