Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit a4480c1

Browse files
committed
Use URIReference in to_host_port_tuple
1 parent 4fff8b4 commit a4480c1

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

hyper/common/util.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
General utility functions for use with hyper.
77
"""
88
from hyper.compat import unicode, bytes, imap
9+
from ..packages.rfc3986.uri import URIReference
910
import re
1011

1112
def to_bytestring(element):
@@ -32,12 +33,16 @@ def to_host_port_tuple(host_port_str, default_port=80):
3233
Converts the given string containing a host and possibly a port
3334
to a tuple.
3435
"""
35-
if re.search("\]:\d+|\.\d{1-3}:\d+|[a-zA-Z0-9-]+:\d+", host_port_str):
36-
host, port = host_port_str.rsplit(':', 1)
37-
port = int(port)
38-
else:
39-
host, port = host_port_str, default_port
36+
uri = URIReference(scheme=None,
37+
authority=host_port_str,
38+
path=None,
39+
query=None,
40+
fragment=None)
4041

41-
host = host.strip('[]')
42+
host = uri.host
43+
if not uri.port:
44+
port = default_port
45+
else:
46+
port = int(uri.port)
4247

4348
return ((host, port))

0 commit comments

Comments
 (0)