Merge pull request #2557 from xonsh/teenc

Give sensible defaults when encoding bytes
This commit is contained in:
Gil Forsyth 2017-12-09 15:03:31 -05:00 committed by GitHub
commit ff05ec33a2
Failed to generate hash of commit
2 changed files with 19 additions and 4 deletions

13
news/teenc.rst Normal file
View file

@ -0,0 +1,13 @@
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:**
* Addressed issue where encoding and errors were None when teeing output.
**Security:** None

View file

@ -42,10 +42,11 @@ class _TeeStdBuf(io.RawIOBase):
The in memory stream buffer.
encoding : str or None, optional
The encoding of the stream. Only used if stdbuf is a text stream,
rather than a binary one.
rather than a binary one. Defaults to $XONSH_ENCODING if None.
errors : str or None, optional
The error form for the encoding of the stream. Only used if stdbuf
is a text stream, rather than a binary one.
is a text stream, rather than a binary one. Deafults to
$XONSH_ENCODING_ERRORS if None.
prestd : bytes, optional
The prefix to prepend to the standard buffer.
poststd : bytes, optional
@ -53,8 +54,9 @@ class _TeeStdBuf(io.RawIOBase):
"""
self.stdbuf = stdbuf
self.membuf = membuf
self.encoding = encoding
self.errors = errors
env = builtins.__xonsh_env__
self.encoding = env.get('XONSH_ENCODING') if encoding is None else encoding
self.errors = env.get('XONSH_ENCODING_ERRORS') if errors is None else errors
self.prestd = prestd
self.poststd = poststd
self._std_is_binary = not hasattr(stdbuf, 'encoding')