tools/utils: Fix issue with loading json files as ascii on python3 linux

pull/8177/head
Andrew Leech 2018-09-19 18:03:02 +10:00
parent 8b623156e5
commit 41ff7b916b
1 changed files with 4 additions and 3 deletions

View File

@ -30,6 +30,7 @@ import json
from collections import OrderedDict from collections import OrderedDict
import logging import logging
from intelhex import IntelHex from intelhex import IntelHex
import io
try: try:
unicode unicode
@ -367,9 +368,9 @@ def json_file_to_dict(fname):
fname - the name of the file to parse fname - the name of the file to parse
""" """
try: try:
with open(fname, "r") as file_obj: with io.open(fname, encoding='ascii',
return json.loads(file_obj.read().encode('ascii', 'ignore'), errors='ignore') as file_obj:
object_pairs_hook=OrderedDict) return json.load(file_obj, object_pairs_hook=OrderedDict)
except (ValueError, IOError): except (ValueError, IOError):
sys.stderr.write("Error parsing '%s':\n" % fname) sys.stderr.write("Error parsing '%s':\n" % fname)
raise raise