eric6/WebBrowser/SafeBrowsing/SafeBrowsingUrl.py

changeset 8240
93b8a353c4bf
parent 8207
d359172d11be
equal deleted inserted replaced
8239:59a9a658618c 8240:93b8a353c4bf
11 import posixpath 11 import posixpath
12 import socket 12 import socket
13 import struct 13 import struct
14 import hashlib 14 import hashlib
15 import urllib.parse 15 import urllib.parse
16 import contextlib
16 17
17 import Preferences 18 import Preferences
18 19
19 20
20 class SafeBrowsingUrl: 21 class SafeBrowsingUrl:
105 path += '/' 106 path += '/'
106 port = urlParts.port 107 port = urlParts.port
107 host = host.strip('.') 108 host = host.strip('.')
108 host = re.sub(r'\.+', '.', host).lower() 109 host = re.sub(r'\.+', '.', host).lower()
109 if host.isdigit(): 110 if host.isdigit():
110 try: 111 with contextlib.suppress(Exception):
111 host = socket.inet_ntoa(struct.pack("!I", int(host))) 112 host = socket.inet_ntoa(struct.pack("!I", int(host)))
112 except Exception: # secok
113 pass
114 if host.startswith('0x') and '.' not in host: 113 if host.startswith('0x') and '.' not in host:
115 try: 114 with contextlib.suppress(Exception):
116 host = socket.inet_ntoa(struct.pack("!I", int(host, 16))) 115 host = socket.inet_ntoa(struct.pack("!I", int(host, 16)))
117 except Exception: # secok
118 pass
119 quotedPath = quote(path) 116 quotedPath = quote(path)
120 quotedHost = quote(host) 117 quotedHost = quote(host)
121 if port is not None: 118 if port is not None:
122 quotedHost = '{0}:{1}'.format(quotedHost, port) 119 quotedHost = '{0}:{1}'.format(quotedHost, port)
123 canonicalUrl = '{0}://{1}{2}'.format(protocol, quotedHost, quotedPath) 120 canonicalUrl = '{0}://{1}{2}'.format(protocol, quotedHost, quotedPath)

eric ide

mercurial