summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--jsonschema/_utils.py13
-rw-r--r--setup.cfg1
2 files changed, 11 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):
diff --git a/setup.cfg b/setup.cfg
index 7dd8e38..e9e3efe 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -28,6 +28,7 @@ python_requires = >=3.7
install_requires =
attrs>=17.4.0
importlib_metadata;python_version<'3.8'
+ importlib_resources;python_version<'3.9'
pyrsistent>=0.14.0,!=0.17.0,!=0.17.1,!=0.17.2
[options.extras_require]