[PATCH] More non-ASCII environment cleanups
Jan Hudec
bulb at ucw.cz
Wed Oct 26 08:31:59 BST 2005
On Mon, Oct 24, 2005 at 22:11:44 +0200, Joel Rosdahl wrote:
> Hi,
>
> Here is another patch that tries to fix a bunch of non-ASCII
> environment issues. It touches many parts of bzr, so a careful review
> is probably needed if someone wants to integrate it.
>
> My litmus test for the changes has been to make "bzr selftest" work in
> a directory with non-ASCII (and non-ISO-8859-1) characters. And with
> this patch the selftests pass, at least on my Debian box with
> an en_GB.UTF-8 locale.
>
> A note about the patch:
>
> There are lots of places in the current bzr code where the print
> statement is used to write Unicode strings to standard output. But
> that doesn't work when sys.stdout.encoding isn't set (and it isn't
> always, for example if standard output is redirected to a file).
> Therefore, I created a function called bzrlib.osutils.myprint (I
> wouldn't mind a better name or another location) and replaced many of
> the print statements with it. For consistency reasons, myprint is also
> used to print integers and ASCII-safe strings in some places.
Why don't you just set sys.stdout.encoding if it is not set. IMHO this
python only setting it only if it is a terminal is broken. I'd say
bzrlib should require it being set and bzr should set it.
Another problem might be the error handling for encode, since it does
not seem to be possible to change it in print.
> (I guess an alternative solution would be to rebind sys.stdout to an
> encoding wrapper, but I thought that wouldn't be appropriate for a
> library. A third solution would be to create an encoding wrapper and
> make it easily available so that code that wants to print strings just
> calls write() on the wrapper directly, but it felt like more work.)
--
Jan 'Bulb' Hudec <bulb at ucw.cz>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051026/8b47f9c2/attachment.pgp
More information about the bazaar
mailing list