From 7241db0d5e0be9a43acde2743f68a5182b3f97ed Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sun, 15 Mar 2015 17:51:07 -0400 Subject: [PATCH] Fix base_uri backwards compatibility. --- jsonschema/tests/test_validators.py | 2 ++ jsonschema/validators.py | 5 +++++ 2 files changed, 7 insertions(+) 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