Question about propagating universal_newlines through subprocess.Popen to io.TextIOWrapper
eryk sun
eryksun at gmail.com
Mon Jun 26 15:44:21 EDT 2017
On Mon, Jun 26, 2017 at 5:23 PM, Bill Deegan <bill at baddogconsulting.com> wrote:
>
> That universal_newlines value is discarded due to:
>
> text_mode = encoding or errors or universal_newlines
>
> ...
>
> if text_mode:
> self.stdout = io.TextIOWrapper(self.stdout,
> encoding=encoding, errors=errors)
>
> There doesn't seem to be a way to set encoding without forcing
> univeral_newlines.
>
> This seems like a bug?
The behavior is documented:
If encoding or errors are specified, or universal_newlines is true,
the file objects stdin, stdout and stderr will be opened in text
mode using the encoding and errors specified in the call or the
defaults for io.TextIOWrapper.
For stdin, line ending characters '\n' in the input will be
converted to the default line separator os.linesep. For stdout and
stderr, all line endings in the output will be converted to '\n'.
For more information see the documentation of the io.TextIOWrapper
class when the newline argument to its constructor is None.
Prior to 3.6, the way to get text streams was to enable
universal_newlines. Maybe for 3.7 the default can change to None, with
the addition of the following code:
if universal_newlines is None or universal_newlines:
newline = None
else:
newline = ''
if text_mode:
self.stdin = io.TextIOWrapper(self.stdin, write_through=True,
line_buffering=(bufsize == 1),
encoding=encoding, errors=errors, newline=newline)
More information about the Python-list
mailing list