[rfc] about encodings and redirect output of bzr via pipe

Alexander Belchenko bialix at ukr.net
Sat Apr 29 21:00:24 BST 2006


Probably I found the solution for problem of determining actual encoding
of console when bzr output redirecting to pager ('less' or 'more') via
pipe. E.g. command:

$ bzr log | less

When do this redirection then shell connect stdout of bzr process to
stdin of next process. So sys.stdout lost 'encoding' attribute. And
therefore information of actual encoding of console is lost. So, my
previous approach to fix problem with 'cp866' <-> 'cp1251' on russian
windows relying on sys.stdout.encoding was vulnerable by pipe.

But this problem can be solved if using sys.stdin.encoding when
sys.stdout.encoding is not exists. At least on my win32 machine it works
as expected:

E:\work\Python\sketches\stdin>test_encodings.py
<stdin> encoding: cp866
<stdout> encoding: cp866
<stderr> encoding: None

E:\work\Python\sketches\stdin>test_encodings.py | more
<stdin> encoding: cp866
<stdout> encoding: None
<stderr> encoding: None

I think this approach is platform-safe, not exclusively for win32, do you?

In attachment you can find testing script test_encodings.py.

Now I try to pull John Meinel's encodings branch and will review his
encoding patch. And I probably want to make addition based on my
experiment with sys.stdin.encoding above.

--
Alexander

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_encodings.py
Url: https://lists.ubuntu.com/archives/bazaar/attachments/20060429/ffff91d5/attachment.diff 


More information about the bazaar mailing list