diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2013-09-16 06:55:33 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2013-09-16 06:55:41 +0200 |
commit | 7459e3a29081dfa4cbbcc795e054e884e1d5e020 (patch) | |
tree | 2705a0a0fbcc03e6ab3d0c278f4b0b8c59d9a44f /youtube_dl/utils.py | |
parent | f9e66fb99367b5ccac3f0c1c61441ed52d787836 (diff) |
Always correct encoding when writing to sys.stderr (Fixes #1435)
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 5558d4737..814a9b6be 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -790,6 +790,18 @@ def platform_name(): return res +def write_string(s, out=None): + if out is None: + out = sys.stderr + assert type(s) == type(u'') + + if ('b' in getattr(out, 'mode', '') or + sys.version_info[0] < 3): # Python 2 lies about mode of sys.stderr + s = s.encode(preferredencoding(), 'ignore') + out.write(s) + out.flush() + + def bytes_to_intlist(bs): if not bs: return [] |