diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2014-08-21 18:01:33 +0200 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2014-08-21 18:01:33 +0200 |
commit | cab317a6804f9ca5a7de71e6baae5d6b32ddf053 (patch) | |
tree | e094c592569adb4da8589b5a7b6e593e4dbd24fe /youtube_dl/utils.py | |
parent | c15235cd073c3dd7d796e36c69cc5ec67f97ffe7 (diff) | |
parent | 73159f99cc3be44b207154ecd56d16750cade77a (diff) | |
download | youtube-dl-cab317a6804f9ca5a7de71e6baae5d6b32ddf053.tar.xz |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'youtube_dl/utils.py')
-rw-r--r-- | youtube_dl/utils.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index d11e46c80..f8ec5389f 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -233,18 +233,24 @@ else: def write_json_file(obj, fn): """ Encode obj as JSON and write it to fn, atomically """ + args = { + 'suffix': '.tmp', + 'prefix': os.path.basename(fn) + '.', + 'dir': os.path.dirname(fn), + 'delete': False, + } + # 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): - mode = 'wb' - encoding = None + args['mode'] = 'wb' else: - mode = 'w' - encoding = 'utf-8' - tf = tempfile.NamedTemporaryFile( - suffix='.tmp', prefix=os.path.basename(fn) + '.', - dir=os.path.dirname(fn), - delete=False) + args.update({ + 'mode': 'w', + 'encoding': 'utf-8', + }) + + tf = tempfile.NamedTemporaryFile(**args) try: with tf: |