[Zope] Unicode Error

Tino Wildenhain tino@wildenhain.de
Sat, 02 Nov 2002 02:48:54 +0100


Hi Dieter, Toby, Juan,

--On Freitag, 1. November 2002 18:18 +0100 Dieter Maurer 
<dieter@handshake.de> wrote:

> Toby Dickenson writes:
>  > ...
>  > ... setdefaultencoding ...
>  > It is likely to disappear in fu
>  > ture
>  > versions of python. Alot of code legitimately assumes the default
> encodin  > g is
>  > ascii, and may break if you change it.
> This would be a bad turn on Python's part.
>
>    For the time being, the encoding used in may files, the printer,
>    the operating system is "latin-1".
>
>    Python should provide a convenient way to transparently convert
>    between Unicode and my default environment, when I tell is so.
>
>    Hopefully, we can prevent this turn into Americanims!

I dont know why this code is in site.py:

encoding = "ascii" # Default value set by _PyUnicode_Init()

if 0:
    # Enable to support locale aware default string encodings.
    import locale
    loc = locale.getdefaultlocale()
    if loc[1]:
        encoding = loc[1]

if 0:
    # Enable to switch off string to Unicode coercion and implicit
    # Unicode to string conversion.
    encoding = "undefined"

if encoding != "ascii":
    sys.setdefaultencoding(encoding)

This implies modification of the installed code to change
default behavior. I would consider this as bad.
Why isnt a locales sensitive version the default?

However, there is lukyly another way to do it:

let us provide a sitecustomize.py module for zope.
If its in the path, it has access to sys.setdefaultencoding

I use it that way (I set utf-8) and Zope unicodes and strings
quite good. Also without the nasty cStringIO -> StringIO patch
in ZPT and friends. However I had to change some things
in ZPublisher/HTTPResponse.py to always get correct charset
in the header.

Also there are some products who use latin-1 per default.
This is a bug to.

Regards
Tino