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) |