def __host_per_rfc_2732(host):
"Format a host name or IP for a URL according to RFC 2732"
try:
socket.inet_pton(socket.AF_INET6, host)
return "[%s]" % (host)
except socket.error:
return host # Not an IPv6 address
文章目录