Skip to content

Commit 9d847bf

Browse files
authored
Merge pull request #95 from handrews/no-warnings
Don't use deprecated methods in resolve_with()
2 parents a58db4c + 7d8059f commit 9d847bf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/rfc3986/_mixin.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ def authority_info(self):
5656
def _match_subauthority(self):
5757
return misc.SUBAUTHORITY_MATCHER.match(self.authority)
5858

59+
@property
60+
def _validator(self):
61+
v = getattr(self, "_cached_validator", None)
62+
if v is not None:
63+
return v
64+
self._cached_validator = validators.Validator().require_presence_of(
65+
"scheme"
66+
)
67+
return self._cached_validator
68+
5969
@property
6070
def host(self):
6171
"""If present, a string representing the host."""
@@ -262,7 +272,9 @@ def resolve_with(self, base_uri, strict=False):
262272
if not isinstance(base_uri, URIMixin):
263273
base_uri = type(self).from_string(base_uri)
264274

265-
if not base_uri.is_valid(require_scheme=True):
275+
try:
276+
self._validator.validate(base_uri)
277+
except exc.ValidationError:
266278
raise exc.ResolutionError(base_uri)
267279

268280
# This is optional per

tests/test_uri.py

+8
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,14 @@ def test_resolve_pathless_query(self, basic_uri):
376376
assert T.path is None
377377
assert T.query == "query"
378378

379+
def test_resolve_twice_for_cached_validator(self, basic_uri):
380+
R = URIReference.from_string("")
381+
B = URIReference.from_string(basic_uri)
382+
T1 = R.resolve_with(B)
383+
T2 = R.resolve_with(B)
384+
assert T1 == T2
385+
assert T1 == B
386+
379387

380388
def test_empty_querystrings_persist():
381389
url = "https://httpbin.org/get?"

0 commit comments

Comments
 (0)