self-hosting repo available

Fredrik Lundh fredrik at pythonware.com
Mon Apr 11 14:37:44 BST 2005


Lele Gaifax wrote:

> As said, this depends on the system setup for Python. You didn't
> mention which distro you're using, but you should be able to locate
> either an /etc/python/site.py or an equivalent somewhere under the
> /usr/lib/python2.3/ tree.
>
> It should contain a call to sys.setdefaultencoding(). Debian does it
> this way:
>
>     encoding = "ascii" # Default value set by _PyUnicode_Init()
>
>     if 1:  ## <------- THIS is 0 by default
>         # Enable to support locale aware default string encodings.
>         import locale
>         loc = locale.getdefaultlocale()
>         if loc[1]:
>             encoding = loc[1]

DO NOT CHANGE THE DEFAULT ENCODING!!!

(unless you can guarantee that no programs written on your machine will ever escape
into the wild without careful testing on a properly configured Python install)

If you want to write portable code, you should decode on the way in, use Unicode
strings on the inside (for anything that can contain non-ASCII text), and encode on
the way out.  You can either do this by hand (by calling decode and encode at the
right places), or via encoded streams (codec.open).  You can use getdefaultlocale
to figure out how to deal with input/output from stdin/stdout, but that's about it; any
approach that requires changing system-wide settings is a recipe for disaster.

(if anyone wants me to look at encoding-aware parts of bzr, let me know)

cheers /F 







More information about the bazaar mailing list