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
This commit is contained in:
parent
3e4fc82843
commit
4a2b7af718
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user