Re: [Zope] Change the encoding of a single ZPT page
2006/8/29, Andreas Jung <lists@zopyx.com>:
--On 29. August 2006 12:28:30 -0300 Luiz Fernando Bernardes Ribeiro <luiz.fernando.ribeiro@gmail.com> wrote:
Hello all,
Is it possible to change the encoding of a page without having to change
the default-zpublisher-encoding option in zope.conf?
My default encoding is iso8859-1 but we have to generate some XML files to a flash app, but flash only accept utf-8.
If you edit your ZPTs through the ZMI you might set the manage_page_charset to utf-8. If the content-type of your ZPT is set to text/xml then the ZPublisher should auto-detect the encoding from the XML preamble. The setting in zope.conf is just a fallback (at least in Zope 2.9+).
-aj
After trying a lot of things, I found the problem is really in the zpublisher realm, no matter what kind of encoding trick I use, even with a python script, the output is converted to the default encoding if I use any variable or dynamic value from the database. Changing the 'default-zpublisher-encoding' setting solved the problem but I would have to convert hundreds of iso8859-1 html pages... I have already recoded the XML inside a Python script where I think it will be easier to use any magic zope trick... so I'm asking a way to avoid changing zope.conf to produce this simgle xml file... Python script test.xml: request = container.REQUEST xml = [ ] xml.append('<?xml version="1.0" encoding="utf-8"?>') xml.append('<lista xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:tal="http://xml.zope.org/namespaces/tal">') xml.append('<item palavra="%s" id="%s" />' % (container.sqlPalavras(ID=id)[0].Apelido, id)) xml.append('</lista>') print unicode("\n".join(xml), 'iso8859-1') return printed I'm using Zope 2.9. Thanks in advance for your help and time, -- Luiz Fernando B. Ribeiro
2006/8/30, Luiz Fernando Bernardes Ribeiro <luiz.fernando.ribeiro@gmail.com
:
2006/8/29, Andreas Jung <lists@zopyx.com>:
--On 29. August 2006 12:28:30 -0300 Luiz Fernando Bernardes Ribeiro <luiz.fernando.ribeiro@gmail.com > wrote:
Hello all,
Is it possible to change the encoding of a page without having to change the default-zpublisher-encoding option in zope.conf?
My default encoding is iso8859-1 but we have to generate some XML files to a flash app, but flash only accept utf-8.
If you edit your ZPTs through the ZMI you might set the manage_page_charset to utf-8. If the content-type of your ZPT is set to text/xml then the ZPublisher should auto-detect the encoding from the XML preamble. The setting in zope.conf is just a fallback (at least in Zope 2.9+).
-aj
After trying a lot of things, I found the problem is really in the zpublisher realm, no matter what kind of encoding trick I use, even with a python script, the output is converted to the default encoding if I use any variable or dynamic value from the database. Changing the 'default-zpublisher-encoding' setting solved the problem but I would have to convert hundreds of iso8859-1 html pages...
I have already recoded the XML inside a Python script where I think it will be easier to use any magic zope trick... so I'm asking a way to avoid changing zope.conf to produce this simgle xml file...
Python script test.xml:
request = container.REQUEST xml = [ ]
xml.append('<?xml version="1.0" encoding="utf-8"?>') xml.append('<lista xmlns:metal="http://xml.zope.org/namespaces/metal" xmlns:tal=" http://xml.zope.org/namespaces/tal">')
xml.append('<item palavra="%s" id="%s" />' % ( container.sqlPalavras(ID=id)[0].Apelido, id))
xml.append('</lista>')
print unicode("\n".join(xml), 'iso8859-1') return printed
I'm using Zope 2.9.
Thanks in advance for your help and time,
-- Luiz Fernando B. Ribeiro
Solved!! Using curl I found the problem was really the HTTP headers and the solution was always there in my face, in ZMI change the Content-type property to 'text/xml; charset=utf-8'. Simple and easy... Thanks all, -- Luiz Fernando B. Ribeiro
Luiz Fernando Bernardes Ribeiro wrote: [...]
Solved!! Using curl I found the problem was really the HTTP headers and the solution was always there in my face, in ZMI change the Content-type property to 'text/xml; charset=utf-8'. Simple and easy...
Just make sure you don't run into http://www.zope.org/Collectors/Zope/2110 Cheers, Igor
Luiz Fernando Bernardes Ribeiro wrote at 2006-8-30 14:08 -0300:
2006/8/29, Andreas Jung <lists@zopyx.com>: ... After trying a lot of things, I found the problem is really in the zpublisher realm, no matter what kind of encoding trick I use, even with a python script, the output is converted to the default encoding if I use any variable or dynamic value from the database.
If you were right (which I still hope you won't) than someone severely misunderstood the meaning of "default". "default" means "use this unless you get get told to use something else". And if I tell the ZPublisher (in the "Content-Type" header), that the charset is different from its "default-zpublisher-encoding", then it has to respect this. If it does not, then please file a bug report. -- Dieter
--On 31. August 2006 19:28:54 +0200 Dieter Maurer <dieter@handshake.de> wrote:
Luiz Fernando Bernardes Ribeiro wrote at 2006-8-30 14:08 -0300:
2006/8/29, Andreas Jung <lists@zopyx.com>: ... After trying a lot of things, I found the problem is really in the zpublisher realm, no matter what kind of encoding trick I use, even with a python script, the output is converted to the default encoding if I use any variable or dynamic value from the database.
If you were right (which I still hope you won't) than someone severely misunderstood the meaning of "default".
I think he is not right. -aj
participants (4)
-
Andreas Jung -
Dieter Maurer -
Igor Stroh -
Luiz Fernando Bernardes Ribeiro