[BUNDLE] Make additional chance to obtain right encoding of console when output piped
John Arbash Meinel
john at arbash-meinel.com
Sat Jun 10 14:27:58 BST 2006
Wouter van Heyst wrote:
> On Fri, Jun 09, 2006 at 07:57:49PM +0300, Alexander Belchenko wrote:
>> I wrote about this fact before: when output of bzr command piped to
>> another program, i.e. when run something like:
>>
>> bzr log | less
>>
>> Then sys.stdout lose their own encoding attribute value and bzr switch
>> to use bzrlib.user_encoding value. That behaviour on some system is
>> inappropriate, see bug 5041 as example.
>>
>> But when only stdout piped out then stdin is not touched and behaves
>> normally. So bzr should try to use information from sys.stdin.encoding
>> to detect *right* encoding of console.
>
> This doesn't seem enough for 'bzr pull | less' though.
>
> bzr: ERROR: exceptions.TypeError: encode() argument 1 must be string, not None
> at /home/larstiq/src/bzr/bzr.dev/bzrlib/urlutils.py line 468
> in unescape_for_display
>
> Wouter van Heyst
Actually, I tracked down this bug. The problem is that when you call:
codecs.getwriter(output_encoding)(sys.stdout, errors=self.encoding_type)
It returns a file-like object which will use the supplied
'output_encoding' to transparently encode your strings before sending
them to sys.stdout. It works as a wrapper around any file.
The problem is that it uses __getattr__ to return any special attributes
directly from the wrapped object, but it doesn't set '.encoding' itself.
So even though you have wrapped 'sys.stdout' with something that does
have a proper encoding, checking outf.encoding will return None.
Elsewhere in the code, I assume that 'self.outf.encoding' is correct.
The attached patch just sets the self.outf.encoding to the right value,
so that we can detect it properly later.
This fixes Wouter's 'bzr pull | less' bug.
Seeking a +1
John
=:->
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix-self.outf.encoding.bundle
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20060610/1e6f7c24/attachment.diff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060610/1e6f7c24/attachment.pgp
More information about the bazaar
mailing list