From 4a2b7af7182118923c68a49be897c15c71fed56f Mon Sep 17 00:00:00 2001 From: Andrey Volkov Date: Mon, 24 Dec 2018 12:12:17 +0300 Subject: [PATCH] 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 --- lower-constraints.txt | 2 +- oslo_config/types.py | 21 ++++++++++++--------- requirements.txt | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lower-constraints.txt b/lower-constraints.txt index 828392f0..ad6177e2 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -40,7 +40,7 @@ reno==2.5.0 requests==2.18.0 requests_mock==1.5.0 requestsexceptions==1.2.0 -rfc3986==0.3.1 +rfc3986==1.2.0 six==1.10.0 smmap==0.9.0 snowballstemmer==1.2.1 diff --git a/oslo_config/types.py b/oslo_config/types.py index 4cfe527c..388a4481 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. diff --git a/requirements.txt b/requirements.txt index 7bc89a2a..fd6c874a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,7 +7,7 @@ netaddr>=0.7.18 # BSD six>=1.10.0 # MIT stevedore>=1.20.0 # Apache-2.0 oslo.i18n>=3.15.3 # Apache-2.0 -rfc3986>=0.3.1 # Apache-2.0 +rfc3986>=1.2.0 # Apache-2.0 PyYAML>=3.12 # MIT enum34>=1.0.4;python_version=='2.7' or python_version=='2.6' or python_version=='3.3' # BSD requests>=2.18.0 # Apache-2.0