mirror of https://github.com/ARMmbed/mbed-os.git
tools/utils: Fix issue with loading json files as ascii on python3 linux
parent
8b623156e5
commit
41ff7b916b
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue