mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-05 17:00:58 +01:00
Merge pull request #1884 from bobhy/stderr_no_buffer
Fix AttributeError: 'TextTranscodingWrapper' object has no attribute 'buffer' in stderr
This commit is contained in:
commit
e3c4b0f5c0
2 changed files with 21 additions and 1 deletions
13
news/fix_stderr_attribute_error.rst
Normal file
13
news/fix_stderr_attribute_error.rst
Normal 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
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue