Fix writing JSON on Python 2

This commit is contained in:
Thomas Kluyver 2014-10-20 14:56:10 -07:00
parent 425d5a1c02
commit c26b0f6961

View File

@ -7,6 +7,7 @@ import os
import io
from tornado import web
from IPython.utils.py3compat import PY3
from ...base.handlers import IPythonHandler, json_errors
def recursive_update(target, new):
@ -68,8 +69,13 @@ class ConfigHandler(IPythonHandler):
update = self.get_json_body()
recursive_update(section, update)
with io.open(filename, 'w', encoding='utf-8') as f:
if PY3:
f = io.open(filename, 'w', encoding='utf-8')
else:
f = open(filename, 'wb')
with f:
json.dump(section, f)
self.set_status(204)