Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Read bytes to avoid ijson deprecation & chore: Remove unreachable code. #460

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions flattentool/json_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ class BadlyFormedJSONError(FlattenToolError, ValueError):


class BadlyFormedJSONErrorUTF8(BadlyFormedJSONError):
"""
Deprecated. This exception is no longer raised.
"""

pass


Expand Down Expand Up @@ -302,16 +306,14 @@ 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)

try:
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()
Expand Down
9 changes: 1 addition & 8 deletions flattentool/tests/test_json_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
Loading