mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-24 13:46:53 +01:00
Use our own encoding when writing strings
This commit is contained in:
parent
c3855d28b0
commit
104aa7388a
@ -917,21 +917,14 @@ def write_string(s, out=None, encoding=None):
|
|||||||
|
|
||||||
if ('b' in getattr(out, 'mode', '') or
|
if ('b' in getattr(out, 'mode', '') or
|
||||||
sys.version_info[0] < 3): # Python 2 lies about mode of sys.stderr
|
sys.version_info[0] < 3): # Python 2 lies about mode of sys.stderr
|
||||||
s = s.encode(encoding or preferredencoding(), 'ignore')
|
byt = s.encode(encoding or preferredencoding(), 'ignore')
|
||||||
try:
|
out.write(byt)
|
||||||
out.write(s)
|
elif hasattr(out, 'buffer'):
|
||||||
except UnicodeEncodeError:
|
enc = encoding or getattr(out, 'encoding', None) or preferredencoding()
|
||||||
# In Windows shells, this can fail even when the codec is just charmap!?
|
byt = s.encode(enc, 'ignore')
|
||||||
# See https://wiki.python.org/moin/PrintFails#Issue
|
out.buffer.write(byt)
|
||||||
if sys.platform == 'win32':
|
|
||||||
if not encoding and hasattr(out, 'encoding'):
|
|
||||||
encoding = out.encoding
|
|
||||||
if encoding:
|
|
||||||
b = s.encode(encoding, 'ignore').decode(encoding)
|
|
||||||
out.write(b)
|
|
||||||
else:
|
else:
|
||||||
raise
|
out.write(s)
|
||||||
|
|
||||||
out.flush()
|
out.flush()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user