[BUNDLE] Make additional chance to obtain right encoding of console when output piped

Robert Collins robertc at robertcollins.net
Sat Jun 10 17:39:28 BST 2006


On Sat, 2006-06-10 at 08:27 -0500, John Arbash Meinel wrote:
> 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

+1

Rob
-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060611/d21517cd/attachment.pgp 


More information about the bazaar mailing list