1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

prevent crash when sys.stdout and co. are None (#653)

This commit is contained in:
Mike Fährmann 2020-03-23 23:38:55 +01:00
parent d47d0f757c
commit 4bc161ca0f
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 8 additions and 7 deletions

View File

@ -108,7 +108,7 @@ def parse_inputfile(file, log):
def main():
try:
if sys.stdout.encoding.lower() != "utf-8":
if sys.stdout and sys.stdout.encoding.lower() != "utf-8":
output.replace_std_streams()
parser = option.build_parser()

View File

@ -149,12 +149,13 @@ def replace_std_streams(errors="replace"):
"""Replace standard streams and set their error handlers to 'errors'"""
for name in ("stdout", "stdin", "stderr"):
stream = getattr(sys, name)
setattr(sys, name, stream.__class__(
stream.buffer,
errors=errors,
newline=stream.newlines,
line_buffering=stream.line_buffering,
))
if stream:
setattr(sys, name, stream.__class__(
stream.buffer,
errors=errors,
newline=stream.newlines,
line_buffering=stream.line_buffering,
))
# --------------------------------------------------------------------