mirror of https://github.com/mahmoud/boltons.git
Merge pull request #152 from zeroSteiner/ipv6-with-ports
Correctly handle RFC2732 IPv6 address literals with ports
This commit is contained in:
commit
2b3789948a
|
@ -898,16 +898,19 @@ def parse_url(url_text):
|
|||
if hostinfo:
|
||||
host, sep, port_str = hostinfo.partition(u':')
|
||||
if sep:
|
||||
if u']' in port_str:
|
||||
host = hostinfo # wrong split, was an ipv6
|
||||
else:
|
||||
try:
|
||||
port = int(port_str)
|
||||
except ValueError:
|
||||
if port_str: # empty ports ok according to RFC 3986 6.2.3
|
||||
raise URLParseError('expected integer for port, not %r'
|
||||
% port_str)
|
||||
port = None
|
||||
if host and host[0] == u'[' and u']' in port_str:
|
||||
host_right, _, port_str = port_str.partition(u']')
|
||||
host = host + u':' + host_right + u']'
|
||||
if port_str and port_str[0] == u':':
|
||||
port_str = port_str[1:]
|
||||
|
||||
try:
|
||||
port = int(port_str)
|
||||
except ValueError:
|
||||
if port_str: # empty ports ok according to RFC 3986 6.2.3
|
||||
raise URLParseError('expected integer for port, not %r'
|
||||
% port_str)
|
||||
port = None
|
||||
|
||||
family, host = parse_host(host)
|
||||
|
||||
|
|
Loading…
Reference in New Issue