urlutils: Raise exception on errors in host_tuple.
This commit is contained in:
parent
6f904759b5
commit
269676318b
@ -195,10 +195,20 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
errors = [SslError(e) for e in errors]
|
errors = [SslError(e) for e in errors]
|
||||||
ssl_strict = config.get('network', 'ssl-strict')
|
ssl_strict = config.get('network', 'ssl-strict')
|
||||||
if ssl_strict == 'ask':
|
if ssl_strict == 'ask':
|
||||||
|
try:
|
||||||
host_tpl = urlutils.host_tuple(reply.url())
|
host_tpl = urlutils.host_tuple(reply.url())
|
||||||
if set(errors).issubset(self._accepted_ssl_errors[host_tpl]):
|
except ValueError:
|
||||||
|
host_tpl = None
|
||||||
|
is_accepted = False
|
||||||
|
is_rejected = False
|
||||||
|
else:
|
||||||
|
is_accepted = set(errors).issubset(
|
||||||
|
self._accepted_ssl_errors[host_tpl])
|
||||||
|
is_rejected = set(errors).issubset(
|
||||||
|
self._rejected_ssl_errors[host_tpl])
|
||||||
|
if is_accepted:
|
||||||
reply.ignoreSslErrors()
|
reply.ignoreSslErrors()
|
||||||
elif set(errors).issubset(self._rejected_ssl_errors[host_tpl]):
|
elif is_rejected:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
err_string = '\n'.join('- ' + err.errorString() for err in
|
err_string = '\n'.join('- ' + err.errorString() for err in
|
||||||
@ -208,9 +218,11 @@ class NetworkManager(QNetworkAccessManager):
|
|||||||
owner=reply)
|
owner=reply)
|
||||||
if answer:
|
if answer:
|
||||||
reply.ignoreSslErrors()
|
reply.ignoreSslErrors()
|
||||||
self._accepted_ssl_errors[host_tpl] += errors
|
d = self._accepted_ssl_errors
|
||||||
else:
|
else:
|
||||||
self._rejected_ssl_errors[host_tpl] += errors
|
d = self._rejected_ssl_errors
|
||||||
|
if host_tpl is not None:
|
||||||
|
d[host_tpl] += errors
|
||||||
elif ssl_strict:
|
elif ssl_strict:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
@ -350,11 +350,29 @@ def filename_from_url(url):
|
|||||||
|
|
||||||
|
|
||||||
def host_tuple(url):
|
def host_tuple(url):
|
||||||
"""Get a (scheme, host, port) tuple.
|
"""Get a (scheme, host, port) tuple from a QUrl.
|
||||||
|
|
||||||
This is suitable to identify a connection, e.g. for SSL errors.
|
This is suitable to identify a connection, e.g. for SSL errors.
|
||||||
"""
|
"""
|
||||||
return (url.scheme(), url.host(), url.port())
|
if not url.isValid():
|
||||||
|
raise ValueError(get_errstring(url))
|
||||||
|
scheme, host, port = url.scheme(), url.host(), url.port()
|
||||||
|
assert scheme
|
||||||
|
if not host:
|
||||||
|
raise ValueError("Got URL {} without host.".format(
|
||||||
|
url.toDisplayString()))
|
||||||
|
if port == -1:
|
||||||
|
port_mapping = {
|
||||||
|
'http': 80,
|
||||||
|
'https': 443,
|
||||||
|
'ftp': 21,
|
||||||
|
}
|
||||||
|
try:
|
||||||
|
port = port_mapping[scheme]
|
||||||
|
except KeyError:
|
||||||
|
raise ValueError("Got URL {} with unknown port.".format(
|
||||||
|
url.toDisplayString()))
|
||||||
|
return scheme, host, port
|
||||||
|
|
||||||
|
|
||||||
def get_errstring(url, base="Invalid URL"):
|
def get_errstring(url, base="Invalid URL"):
|
||||||
|
Loading…
Reference in New Issue
Block a user