[Zope] zpt encoding and content-type

Dieter Maurer dieter at handshake.de
Sat Oct 25 15:55:40 EDT 2003


Bernd Dorn wrote at 2003-10-23 12:33 +0200:
 > Dieter Maurer wrote:
 > > Bernd Dorn wrote at 2003-10-22 11:07 +0200:
 > >  > 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
 > >  > 
 > >  > i tried the suggestion on zopelabs, to set it like the following 
 > >  > somewhere in a tal:replace::
 > >  > 
 > >  >   python:request.response.setHeader ...
 > > 
 > > I should give you an "AttributeError", as "response" needs to
 > > be spelled "RESPONSE".
 > > 
 > 
 > this is not true, because the response object is in the attribute 
 > 'response' of the request, it is just called RESPONSE if it is catched 
 > as a kw argument

You are right: you can use both "response" as well as "RESPONSE".

 > ...
 > > Otherwise, ensure that all non-ASCII strings are unicode strings
 > > and set the correct "Content-Type" header (including the correct
 > > charset). In this case, ZPublisher should automatically
 > > encode the result correctly. Search for "unicode support" on Zope.org.

 > ...
 > the problem for me is not actually the encoding of the pt file, it is 
 > the encoding of the attributes of zope objects (e.g. title), which i 
 > always have to convert to unicode if a non ascii charecter is in and if 
 > the attribute is not a unicode one.
 > 
 > only if i set the encoding in the xml declaration it works without 
 > converting , but then the result is also xml, what is not what i want, 
 > because browsers display the result differently then.

Since Zope 2.6, properties can have unicode types (ustring, ulines, ...).
In this case, Zope converts for you "at the boundaries".

You should find some documentation on Zopes Unicode support (--> zope.org).
It should also explain why it is good to encode/decode only at the
boundaries.

-- 
Dieter



More information about the Zope mailing list