From 4a2b7af7182118923c68a49be897c15c71fed56f Mon Sep 17 00:00:00 2001 From: Andrey Volkov Date: Mon, 24 Dec 2018 12:12:17 +0300 Subject: Resolve deprecation warning for rfc3986 uri validation rfc3986.is_valid_uri is deprecated in 1.1.0. That generates a lot of warnings: "Please use rfc3986.validators.Validator instead. This method will be eventually removed.". This patch updates URI type to use rfc3986.validators. ValueError exception is preserved. Change-Id: Ida56dfa17fca0080b74c1a80d5420ebed203431f --- oslo_config/types.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'oslo_config') diff --git a/oslo_config/types.py b/oslo_config/types.py index 4cfe527..388a448 100644 --- a/oslo_config/types.py +++ b/oslo_config/types.py @@ -879,20 +879,23 @@ class URI(ConfigType): self.schemes = schemes def __call__(self, value): - if not rfc3986.is_valid_uri(value, require_scheme=True, - require_authority=True): - raise ValueError('invalid URI: %r' % value) + uri = rfc3986.uri_reference(value) + validator = rfc3986.validators.Validator().require_presence_of( + 'scheme', 'host', + ).check_validity_of( + 'scheme', 'host', 'path', + ) + if self.schemes: + validator = validator.allow_schemes(*self.schemes) + try: + validator.validate(uri) + except rfc3986.exceptions.RFC3986Exception as exc: + raise ValueError(exc) if self.max_length is not None and len(value) > self.max_length: raise ValueError("Value '%s' exceeds maximum length %d" % (value, self.max_length)) - if self.schemes: - scheme = rfc3986.uri_reference(value).scheme - if scheme not in self.schemes: - raise ValueError("URI scheme '%s' not in %s" % - (scheme, self.schemes)) - # NOTE(dhellmann): self.value is deprecated, and we don't want # to trigger a deprecation warning ourselves so we modify # self._value directly. -- cgit v1.2.1