Skip to content

Commit 7241db0

Browse files
committed
Fix base_uri backwards compatibility.
1 parent ee1a256 commit 7241db0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

jsonschema/tests/test_validators.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ def test_it_retrieves_unstored_refs_via_urlopen(self):
810810
def test_it_can_construct_a_base_uri_from_a_schema(self):
811811
schema = {"id" : "foo"}
812812
resolver = RefResolver.from_schema(schema)
813+
self.assertEqual(resolver.base_uri, "foo")
813814
self.assertEqual(resolver.resolution_scope, "foo")
814815
with resolver.resolving("") as resolved:
815816
self.assertEqual(resolved, schema)
@@ -823,6 +824,7 @@ def test_it_can_construct_a_base_uri_from_a_schema(self):
823824
def test_it_can_construct_a_base_uri_from_a_schema_without_id(self):
824825
schema = {}
825826
resolver = RefResolver.from_schema(schema)
827+
self.assertEqual(resolver.base_uri, "")
826828
self.assertEqual(resolver.resolution_scope, "")
827829
with resolver.resolving("") as resolved:
828830
self.assertEqual(resolved, schema)

jsonschema/validators.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ def pop_scope(self):
288288
def resolution_scope(self):
289289
return self._scopes_stack[-1]
290290

291+
# backwards compatibility
292+
@property
293+
def base_uri(self):
294+
uri, _ = urldefrag(self.resolution_scope)
295+
return uri
291296

292297
# Deprecated, this function is no longer used, but is preserved for
293298
# backwards compatibility

0 commit comments

Comments
 (0)