Fix utf8 errors

Fix #681
This commit is contained in:
Julien Duponchelle 2016-09-18 22:23:52 +02:00
parent ac8bd3fec4
commit cf10f02a8d
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 3 additions and 3 deletions

View File

@ -648,7 +648,7 @@ class Project:
topo = project_to_topology(self) topo = project_to_topology(self)
path = self._topology_file() path = self._topology_file()
log.debug("Write %s", path) log.debug("Write %s", path)
with open(path + ".tmp", "w+") as f: with open(path + ".tmp", "w+", encoding="utf-8") as f:
json.dump(topo, f, indent=4, sort_keys=True) json.dump(topo, f, indent=4, sort_keys=True)
shutil.move(path + ".tmp", path) shutil.move(path + ".tmp", path)
except OSError as e: except OSError as e:

View File

@ -89,7 +89,7 @@ def load_topology(path):
""" """
log.debug("Read topology %s", path) log.debug("Read topology %s", path)
try: try:
with open(path) as f: with open(path, encoding="utf-8") as f:
topo = json.load(f) topo = json.load(f)
except (OSError, UnicodeEncodeError, json.JSONDecodeError) as e: except (OSError, UnicodeEncodeError, json.JSONDecodeError) as e:
raise aiohttp.web.HTTPConflict(text="Could not load topology {}: {}".format(path, str(e))) raise aiohttp.web.HTTPConflict(text="Could not load topology {}: {}".format(path, str(e)))
@ -98,7 +98,7 @@ def load_topology(path):
# first we backup the file # first we backup the file
shutil.copy(path, path + ".backup") shutil.copy(path, path + ".backup")
topo = _convert_1_3_later(topo, path) topo = _convert_1_3_later(topo, path)
with open(path, "w+") as f: with open(path, "w+", encoding="utf-8") as f:
json.dump(topo, f) json.dump(topo, f)
elif topo["revision"] > GNS3_FILE_FORMAT_REVISION: elif topo["revision"] > GNS3_FILE_FORMAT_REVISION:
raise aiohttp.web.HTTPConflict(text="This project is designed for a more recent version of GNS3 please update GNS3 to version {} or later".format(topo["version"])) raise aiohttp.web.HTTPConflict(text="This project is designed for a more recent version of GNS3 please update GNS3 to version {} or later".format(topo["version"]))