user_encoding fix
Nir Soffer
nirs at freeshell.org
Mon Feb 20 14:41:34 GMT 2006
On 20/02/2006, at 12:42, Alexander Belchenko wrote:
> No. You're wrong. On windows (and on other system too, I think) we
> should check if sys.stdout have encoding attribute and this attribute
> not None and not 'ascii' and then use it. Otherwise, we should use
> bzrlib.user_encoding. Because when I run bzr from editor that grab
> their
> output then sys.stdout is PIPE and does not have encoding attribute at
> all.
>
> So, I think right code should be as following:
>
> if getattr(sys.stdout, "encoding", "ascii") not in (None, "ascii"):
> encoding = sys.stdout.encoding
> else:
> encoding = bzrlib.user_encoding
Sounds good, but on Mac OS X I get 'US-ASCII', so you need this:
if getattr(sys.stdout, 'encoding', None) not in (None, 'ascii',
'US-ASCII'):
encoding = sys.stdout.encoding
else:
encoding = bzrlib.user_encoding
btw, when running with a pipe, sys.stdout does have encoding and is set
to None.
Best Regards,
Nir Soffer
More information about the bazaar
mailing list