[utils] sanitize_open: Allow any IO stream as stdout

Fixes: https://github.com/yt-dlp/yt-dlp/issues/3298#issuecomment-1181754989
pull/4515/head
pukkandan 2 years ago
parent a6bcaf71fc
commit daef791100
No known key found for this signature in database
GPG Key ID: 7EEE9E1E817D0A39

@ -598,7 +598,9 @@ def sanitize_open(filename, open_mode):
if filename == '-': if filename == '-':
if sys.platform == 'win32': if sys.platform == 'win32':
import msvcrt import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) # stdout may be any IO stream. Eg, when using contextlib.redirect_stdout
with contextlib.suppress(io.UnsupportedOperation):
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
return (sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout, filename) return (sys.stdout.buffer if hasattr(sys.stdout, 'buffer') else sys.stdout, filename)
for attempt in range(2): for attempt in range(2):

Loading…
Cancel
Save