From 97376ec1190ed801e0e75563132e5fcee8f8d891 Mon Sep 17 00:00:00 2001 From: James McKinney <26463+jpmckinney@users.noreply.github.com> Date: Fri, 23 Aug 2024 17:34:04 -0400 Subject: [PATCH] fix: Read bytes to avoid ijson deprecation. ijson doesn't have a special error for UTF-8 errors. --- flattentool/json_input.py | 4 +--- flattentool/tests/test_json_input.py | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/flattentool/json_input.py b/flattentool/json_input.py index bba3a5e..d796f10 100644 --- a/flattentool/json_input.py +++ b/flattentool/json_input.py @@ -302,7 +302,7 @@ def __init__( else: path = root_list_path.replace("/", ".") + ".item" - json_file = codecs.open(json_filename, encoding="utf-8") + json_file = codecs.open(json_filename, "rb") self.root_json_list = ijson.items(json_file, path, map_type=OrderedDict) @@ -310,8 +310,6 @@ def __init__( self.parse() except ijson.common.IncompleteJSONError as err: raise BadlyFormedJSONError(*err.args) - except UnicodeDecodeError as err: - raise BadlyFormedJSONErrorUTF8(*err.args) finally: if json_filename: json_file.close() diff --git a/flattentool/tests/test_json_input.py b/flattentool/tests/test_json_input.py index b15b3da..800f9fb 100644 --- a/flattentool/tests/test_json_input.py +++ b/flattentool/tests/test_json_input.py @@ -35,9 +35,6 @@ def test_jsonparser_bad_json_utf8(): name = os.path.join( os.path.dirname(os.path.realpath(__file__)), "fixtures", "bad-utf8.json" ) - # matches against the special error type - with pytest.raises(BadlyFormedJSONErrorUTF8): - JSONParser(json_filename=name) # matches against our base error type with pytest.raises(BadlyFormedJSONError): JSONParser(json_filename=name)