durusmail: quixote-users: Unicode support for Quixote 2
Unicode support for Quixote 2
2004-09-03
2004-09-03
2004-09-03
2004-09-03
Quixote / mod_python - test workflow?
2004-09-04
Re: R: [Quixote-users] Quixote / mod_python - test workflow?
single word attributes in html.htmltag()
2004-09-05
Re: single word attributes in html.htmltag()
2004-09-06
2004-09-04
2004-09-08
Python Best of Breed web app snippets / small webapps
2004-09-08
2004-09-10
2004-09-09
2004-09-09
2004-09-09
2004-09-09
Unicode support for Quixote 2
Marcin Wojdyr
2004-09-03
> I haven't converted the _c_htmltext module to use unicode strings
> but I think pretty much everything else works:
>
>   http://www.mems-exchange.org/software/files/tmp/q2_unicode.diff
>
> I'd appreciate it if people experienced with international charsets
> could review the design.  It seems to work but I'm pretty ignorant
> of unicode.  When testing, you might want to change
> HTTPResponse.charset attribute to 'UTF-8' instead.

Hi, I tried to patch version 1.0, and there were some problems:

patching file demo/pages.ptl
Hunk #1 succeeded at 5 with fuzz 2.
patching file http_response.py
Hunk #2 succeeded at 126 (offset -6 lines).
Hunk #3 succeeded at 139 with fuzz 1 (offset -7 lines).
Hunk #4 succeeded at 207 (offset -7 lines).
patching file html.py
Hunk #1 succeeded at 3 with fuzz 1.
Hunk #3 FAILED at 26.
1 out of 6 hunks FAILED -- saving rejects to file html.py.rej
patching file util.py
patching file form2/widget.py
patching file publish.py
patching file errors.py
patching file form/form.py
patching file _py_htmltext.py
patching file http_request.py

But hunks that failed were (i'm not sure) only docs, so I tested it.

If there are non-ascii chars in PTL it doesn't work:
  File "/usr/lib/python2.3/site-packages/quixote/publish.py", line 566, in
publish_cgi
    self.publish(sys.__stdin__, sys.__stdout__, sys.__stderr__, os.environ)
  File "/usr/lib/python2.3/site-packages/quixote/publish.py", line 548, in
publish
    request.response.set_body(output)
  File "/usr/lib/python2.3/site-packages/quixote/http_response.py", line
210, in set_body     self.body = unicode(body).encode(self.charset)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 954:
ordinal not in range(128)

I changed
self.body = unicode(body).encode(self.charset)
to:
self.body = str(body).decode("UTF-8").encode(self.charset)
and it works as expected.
I have self.charset=="ISO-8859-2".

Thanks, that was what I needed.

Marcin

--
Marcin Wojdyr  |  http://www.unipress.waw.pl/~wojdyr

reply