hi out there! there's been some discussion about utf-8 vs. unicode strings on the list lately. i'd like to ask if my gained understandings are correct und thus possibly make it clear to others also. i have set my python default encoding to utf-8, i always send http responses from zope as utf-8 (by setting the header like this: tal:define="dummy python:request.RESPONSE.\ setHeader('Content-Type','text/html;; charset=utf-8')" ) so if i'd like to use unicode strings in my zope applications, it's still necessary to convert request variables to unicode by using unicode(REQUEST.foo, 'utf-8'), right? as far as i understodd, the conversion back to utf-8 is handled automagically by zope (if the abovementioned header is set), also correct? thanks in advance for your answers! regards, juergen herrmann _______________________________________________________________________
XLhost.de - eXperts in Linux hosting <<
Juergen Herrmann Weiherweg 10, 93051 Regensburg, Germany Fon: +49 (0)700 XLHOSTDE [0700 95467833] Fax: +49 (0)721 151 463027 ICQ: 27139974 - IRC: #XLhost@quakenet WEB: http://www.XLhost.de
Am Freitag, den 06.05.2005, 19:40 +0200 schrieb Jürgen Herrmann:
hi out there!
there's been some discussion about utf-8 vs. unicode strings on the list lately. i'd like to ask if my gained understandings are correct und thus possibly make it clear to others also.
i have set my python default encoding to utf-8, i always send http responses from zope as utf-8 (by setting the header like this: tal:define="dummy python:request.RESPONSE.\ setHeader('Content-Type','text/html;; charset=utf-8')" )
maybe even better to wrap your template publishing in a script - this would avoid such a moderate ugly code.
so if i'd like to use unicode strings in my zope applications, it's still necessary to convert request variables to unicode by using unicode(REQUEST.foo, 'utf-8'), right?
Yes, or you use :ustring and friends modifier in your forms. See: http://www.zope.org/Members/htrd/howto/unicode-zdg-changes
as far as i understodd, the conversion back to utf-8 is handled automagically by zope (if the abovementioned header is set), also correct?
Yes if you set the header in response and the body is of type unicode. If your body is already encoded, you need to make sure it matches whatever you set in the header. Regards Tino
--On Freitag, 6. Mai 2005 19:40 Uhr +0200 Jürgen Herrmann <Juergen.Herrmann@XLhost.de> wrote:
i have set my python default encoding to utf-8, i always send http responses from zope as utf-8
My personal point on changing the default encoding of Python: don't do it (other people will see this different). As long as you are dealing with really only *one* encoding it might be ok. As soon as you mix different encoding (which happens easily with utf8 and iso-8859-X) you are doomed at some point within your application because you will never know why it some string with some encoding converted to whatever. My strategy if you need unicode: keep the default encoding as it is (ascii) and convert everything internally to Python unicode string - not to utf8 encoded string. Perform every operation internally using unicode strings. Only convert to utf8 on the presentation level (means when you send data back to the client or export data to the filesystem or whatever). Such a clean separation between internal Unicode representation and external representation saves you a lot of trouble. -aj
participants (3)
-
Andreas Jung -
Jürgen Herrmann -
Tino Wildenhain