Add some guard code for places where sys.stdout and stderr are replaced with some other incompatible object

This commit is contained in:
Matt Martz 2018-01-26 15:52:06 -06:00
parent e1bab1ab55
commit 2c847a1849
1 changed files with 8 additions and 2 deletions

View File

@ -165,8 +165,14 @@ except ImportError:
self.flush()
_py3_print = getattr(builtins, 'print')
try:
_py3_utf8_stdout = _Py3Utf8Output(sys.stdout)
_py3_utf8_stderr = _Py3Utf8Output(sys.stderr)
except OSError:
# sys.stdout/sys.stderr is not a compatible stdout/stderr object
# just use it and hope things go ok
_py3_utf8_stdout = sys.stdout
_py3_utf8_stderr = sys.stderr
def to_utf8(v):
"""No-op encode to utf-8 for py3"""