diff options
Diffstat (limited to 'jsonschema/_utils.py')
-rw-r--r-- | jsonschema/_utils.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/jsonschema/_utils.py b/jsonschema/_utils.py index d4524e8..e5051ec 100644 --- a/jsonschema/_utils.py +++ b/jsonschema/_utils.py @@ -2,8 +2,14 @@ from collections.abc import Mapping, MutableMapping, Sequence from urllib.parse import urlsplit import itertools import json -import pkgutil import re +import sys + +# The files() API was added in Python 3.9. +if sys.version_info >= (3, 9): # pragma: no cover + import importlib.resources as resources +else: # pragma: no cover + import importlib_resources as resources class URIDict(MutableMapping): @@ -51,8 +57,9 @@ def load_schema(name): Load a schema from ./schemas/``name``.json and return it. """ - data = pkgutil.get_data("jsonschema", "schemas/{0}.json".format(name)) - return json.loads(data.decode("utf-8")) + path = resources.files(__package__).joinpath(f"schemas/{name}.json") + data = path.read_text(encoding="utf-8") + return json.loads(data) def format_as_index(container, indices): |