This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author akira
Recipients akira, serhiy.storchaka
Date 2014-10-23.12:38:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> This is not related to Python. Terms "character", "string", "text", "file" can have different meaning in different domains. In Python we use Python terminology. There is no such thing as sys.stdin in Posix-compatible shell, because Posix-compatible shell has no the sys module and doesn't use a dot to access attributes.

I use Python terminology (text - Unicode string, binary data - bytes).

Though text vs. binary data distinction is language independent (
it doesn't matter how Unicode type is called in a particular language).

Python can be used to implement `tar`, `gpg`, `ssh`, `7z`, etc. I don't
see what POSIX has anything to do with that fact.

It is very simple actually: 

  text -> encode <character encoding> -> bytes
  bytes -> decode <character encoding> -> text

In most cases text should be human readable.

It doesn't make sense to encode/decode input/output of gpg-like utilities using a character encoding. *Therefore* the notion of 
sys.stdin being a bytes stream (io.BufferedReader) can be useful
in this case.

The lines produced by FileInput are often (after optional processing)
written to sys.stdout. If binary mode is used then FileInput(mode='rb') 
yields bytes therefore it is also useful to consider sys.stdout
a binary stream (io.BufferedWriter) in this case.

It introduces a nice symmetry:

  text FileInput mode -> text streams
  binary FileInput mode -> binary streams

By design, FileInput treats stdin as any other file. It
even supports a special name for it: '-'. A file may be in
binary mode; stdin should be able too.

sys.stdout is used outside of FileInput therefore no changes in 
FileInput itself are necessary but sys.stdin is used inside FileInput
that is why the change is needed.

> Correct solution in this case would be to use the workaround "sys.stdin = 
sys.stdin.detach()" conditionally, only in Python versions which have a bug.

Do you mean every Python 3 version before Python 3.4.1?

Correct solution is to avoid blaming users 
(your fault -> you change your programs) for our mistakes  
and fix the bug in Python itself. The patch is attached.
Date User Action Args
2014-10-23 12:38:24akirasetrecipients: + akira, serhiy.storchaka
2014-10-23 12:38:24akirasetmessageid: <>
2014-10-23 12:38:24akiralinkissue22709 messages
2014-10-23 12:38:23akiracreate