Merge pull request #8177 from andrewleech/tools_json_python3

tools/utils: Fix issue with loading json files as ascii on python3 linux
pull/8364/merge
Cruz Monrreal 2018-10-10 08:42:25 -05:00 committed by GitHub
commit be4bb9f610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

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