Skip to content

Commit c76bc82

Browse files
committed
Update validategeojson that use deprecated code
1 parent 51019df commit c76bc82

File tree

1 file changed

+8
-20
lines changed

1 file changed

+8
-20
lines changed

Diff for: pywps/validator/complexvalidator.py

+8-20
Original file line numberDiff line numberDiff line change
@@ -260,35 +260,23 @@ def validategeojson(data_input, mode):
260260
import json
261261

262262
import jsonschema
263+
import referencing
263264

264265
# this code comes from
265266
# https://github.com/om-henners/GeoJSON_Validation/blob/master/geojsonvalidation/geojson_validation.py
267+
schema_uri = "http://json-schema.org/geojson"
266268
schema_home = os.path.join(_get_schemas_home(), "geojson")
267-
base_schema = os.path.join(schema_home, "geojson.json")
268269

269-
with open(base_schema) as fh:
270-
geojson_base = json.load(fh)
270+
registry = referencing.Registry()
271271

272-
with open(os.path.join(schema_home, "crs.json")) as fh:
273-
crs_json = json.load(fh)
272+
for fn in ["geojson.json", "crs.json", "bbox.json", "geometry.json"]:
273+
with open(os.path.join(schema_home, fn)) as fh:
274+
schema_data = json.load(fh)
275+
registry = registry.with_resource(f"{schema_uri}/{fn}", referencing.Resource(schema_data, referencing.jsonschema.DRAFT4))
274276

275-
with open(os.path.join(schema_home, "bbox.json")) as fh:
276-
bbox_json = json.load(fh)
277277

278-
with open(os.path.join(schema_home, "geometry.json")) as fh:
279-
geometry_json = json.load(fh)
280278

281-
cached_json = {
282-
"http://json-schema.org/geojson/crs.json": crs_json,
283-
"http://json-schema.org/geojson/bbox.json": bbox_json,
284-
"http://json-schema.org/geojson/geometry.json": geometry_json
285-
}
286-
287-
resolver = jsonschema.RefResolver(
288-
"http://json-schema.org/geojson/geojson.json",
289-
geojson_base, store=cached_json)
290-
291-
validator = jsonschema.Draft4Validator(geojson_base, resolver=resolver)
279+
validator = jsonschema.Draft4Validator({"$ref": f"{schema_uri}/geojson.json"}, registry=registry)
292280
try:
293281
validator.validate(json.loads(data_input.stream.read()))
294282
passed = True

0 commit comments

Comments
 (0)