diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2012-12-20 13:13:24 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2012-12-20 13:13:24 +0100 |
commit | f4bfd65ff2bfce77a6953281c037ca8e516b7648 (patch) | |
tree | 1a2347c7039d9acd6539ca7187dd0d7fbe10f8dc /youtube_dl/utils.py | |
parent | 3cc687d486c5fc4710b6fdec4340b7635cec91c9 (diff) |
Correct JSON writing (Closes #596)
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 25b67db06..4e64f327a 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -3,6 +3,7 @@ import gzip import io +import json import locale import os import re @@ -175,6 +176,18 @@ else: assert type(s) == type(u'') print(s) +# In Python 2.x, json.dump expects a bytestream. +# In Python 3.x, it writes to a character stream +if sys.version_info < (3,0): + def write_json_file(obj, fn): + with open(fn, 'wb') as f: + json.dump(obj, f) +else: + def write_json_file(obj, fn): + with open(fn, 'w', encoding='utf-8') as f: + json.dump(obj, f) + + def htmlentity_transform(matchobj): """Transforms an HTML entity to a character. |