Skip to content

Commit

Permalink
rosgraph/network: use urlparse for parsing the port, whick makes ipv6…
Browse files Browse the repository at this point in the history
… possible (#1698)

* rosgraph/network: use urlparse for parsing the port, this makes ipv6 possible

* remove unnecessary assert and comment
  • Loading branch information
cwecht authored and dirk-thomas committed Apr 15, 2019
1 parent 7187221 commit f5654f5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
11 changes: 3 additions & 8 deletions tools/rosgraph/src/rosgraph/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,13 @@ def parse_http_host_and_port(url):
:returns: hostname and port number in URL or 80 (default), ``(str, int)``
:raises: :exc:`ValueError` If the url does not validate
"""
# can't use p.port because that's only available in Python 2.5
if not url:
raise ValueError('not a valid URL')
p = urlparse.urlparse(url)
if not p[0] or not p[1]: #protocol and host
if not p.scheme or not p.hostname:
raise ValueError('not a valid URL')
if ':' in p[1]:
hostname, port = p[1].split(':')
port = int(port)
else:
hostname, port = p[1], 80
return hostname, port
port = p.port if p.port else 80
return p.hostname, port

def _is_unix_like_platform():
"""
Expand Down
1 change: 1 addition & 0 deletions tools/rosgraph/test/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_parse_http_host_and_port(self):
assert ('localhost', 1234) == parse_http_host_and_port('http://localhost:1234')
assert ('localhost', 1) == parse_http_host_and_port('http://localhost:1')
assert ('willowgarage.com', 1) == parse_http_host_and_port('http://willowgarage.com:1')
assert ('FEDC:BA98:7654:3210:FEDC:BA98:7654:3210'.lower(), 81) == parse_http_host_and_port('http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:81')

def test_get_local_address(self):
# mostly a tripwire test
Expand Down

0 comments on commit f5654f5

Please sign in to comment.