diff --git a/CHANGELOG.md b/CHANGELOG.md index c4d0092..20bc107 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- Avoid deprecation warning from the ijson package. https://github.com/OpenDataServices/flatten-tool/pull/458 + ## [0.26.0] - 2024-08-22 ### Fixed diff --git a/flattentool/json_input.py b/flattentool/json_input.py index bba3a5e..3a4309a 100644 --- a/flattentool/json_input.py +++ b/flattentool/json_input.py @@ -47,6 +47,10 @@ class BadlyFormedJSONError(FlattenToolError, ValueError): class BadlyFormedJSONErrorUTF8(BadlyFormedJSONError): + """ + Deprecated. This exception is no longer raised. + """ + pass @@ -302,7 +306,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 +314,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..acfbf15 100644 --- a/flattentool/tests/test_json_input.py +++ b/flattentool/tests/test_json_input.py @@ -8,11 +8,7 @@ import pytest -from flattentool.json_input import ( - BadlyFormedJSONError, - BadlyFormedJSONErrorUTF8, - JSONParser, -) +from flattentool.json_input import BadlyFormedJSONError, JSONParser from flattentool.schema import SchemaParser from flattentool.tests.test_schema_parser import object_in_array_example_properties @@ -35,9 +31,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)