X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=youtube_dl%2Futils.py;h=f8ec5389f4978a6060070be019a176e0deff46d4;hb=73159f99cc3be44b207154ecd56d16750cade77a;hp=d11e46c80d76c2405cdb05d26f056cd45ae27bab;hpb=55db73efdf1860bbd24b8556fbefd2ba6263a2cf;p=youtube-dl 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: