diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 1f03294..cc4bea8 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -810,6 +810,7 @@ class TestRefResolver(unittest.TestCase): def test_it_can_construct_a_base_uri_from_a_schema(self): schema = {"id" : "foo"} resolver = RefResolver.from_schema(schema) + self.assertEqual(resolver.base_uri, "foo") self.assertEqual(resolver.resolution_scope, "foo") with resolver.resolving("") as resolved: self.assertEqual(resolved, schema) @@ -823,6 +824,7 @@ class TestRefResolver(unittest.TestCase): def test_it_can_construct_a_base_uri_from_a_schema_without_id(self): schema = {} resolver = RefResolver.from_schema(schema) + self.assertEqual(resolver.base_uri, "") self.assertEqual(resolver.resolution_scope, "") with resolver.resolving("") as resolved: self.assertEqual(resolved, schema) diff --git a/jsonschema/validators.py b/jsonschema/validators.py index c84a3db..8f35d2b 100644 --- a/jsonschema/validators.py +++ b/jsonschema/validators.py @@ -288,6 +288,11 @@ class RefResolver(object): def resolution_scope(self): return self._scopes_stack[-1] + # backwards compatibility + @property + def base_uri(self): + uri, _ = urldefrag(self.resolution_scope) + return uri # Deprecated, this function is no longer used, but is preserved for # backwards compatibility