prevent crash when sys.stdout and co. are None (#653)
This commit is contained in:
@@ -108,7 +108,7 @@ def parse_inputfile(file, log):
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
if sys.stdout.encoding.lower() != "utf-8":
|
if sys.stdout and sys.stdout.encoding.lower() != "utf-8":
|
||||||
output.replace_std_streams()
|
output.replace_std_streams()
|
||||||
|
|
||||||
parser = option.build_parser()
|
parser = option.build_parser()
|
||||||
|
|||||||
@@ -149,12 +149,13 @@ def replace_std_streams(errors="replace"):
|
|||||||
"""Replace standard streams and set their error handlers to 'errors'"""
|
"""Replace standard streams and set their error handlers to 'errors'"""
|
||||||
for name in ("stdout", "stdin", "stderr"):
|
for name in ("stdout", "stdin", "stderr"):
|
||||||
stream = getattr(sys, name)
|
stream = getattr(sys, name)
|
||||||
setattr(sys, name, stream.__class__(
|
if stream:
|
||||||
stream.buffer,
|
setattr(sys, name, stream.__class__(
|
||||||
errors=errors,
|
stream.buffer,
|
||||||
newline=stream.newlines,
|
errors=errors,
|
||||||
line_buffering=stream.line_buffering,
|
newline=stream.newlines,
|
||||||
))
|
line_buffering=stream.line_buffering,
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
# --------------------------------------------------------------------
|
# --------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user