Merge pull request #1884 from bobhy/stderr_no_buffer

Fix AttributeError: 'TextTranscodingWrapper' object has no attribute 'buffer' in stderr
This commit is contained in:
Anthony Scopatz 2016-10-26 22:04:30 -04:00 committed by GitHub
commit e3c4b0f5c0
2 changed files with 21 additions and 1 deletions

View file

@ -0,0 +1,13 @@
**Added:** None
**Changed:** None
**Deprecated:** None
**Removed:** None
**Fixed:**
* ``proc.stream_stderr`` now handles stderr that doesn't have buffer attribute
**Security:** None

View file

@ -1577,9 +1577,16 @@ class CommandPipeline:
"""Streams lines to sys.stderr and the errors attribute."""
if not lines:
return
env = builtins.__xonsh_env__
enc = env.get('XONSH_ENCODING')
err = env.get('XONSH_ENCODING_ERRORS')
b = b''.join(lines)
stderr_has_buffer = hasattr(sys.stderr, 'buffer')
# write bytes to std stream
sys.stderr.buffer.write(b)
if stderr_has_buffer:
sys.stderr.buffer.write(b)
else:
sys.stderr.write(b.decode(encoding=enc, errors=err))
sys.stderr.flush()
# do some munging of the line before we save it to the attr
b = RE_HIDDEN_BYTES.sub(b'', b)