IPV6 interface binding (#80)

This commit is contained in:
Gennady Chibisov 2017-02-11 05:24:50 +03:00 committed by Andrew Godwin
parent 4d23655b5c
commit 630609fce7
2 changed files with 19 additions and 0 deletions

View File

@ -185,6 +185,7 @@ def build_endpoint_description_strings(
"""
socket_descriptions = []
if host and port:
host = host.strip('[]').replace(':', '\:')
socket_descriptions.append('tcp:port=%d:interface=%s' % (int(port), host))
elif any([host, port]):
raise ValueError('TCP binding requires both port and host kwargs.')

View File

@ -28,6 +28,16 @@ class TestEndpointDescriptions(TestCase):
['tcp:port=8000:interface=127.0.0.1']
)
self.assertEqual(
build(port=8000, host='[200a::1]'),
['tcp:port=8000:interface=200a\:\:1']
)
self.assertEqual(
build(port=8000, host='200a::1'),
['tcp:port=8000:interface=200a\:\:1']
)
# incomplete port/host kwargs raise errors
self.assertRaises(
ValueError,
@ -123,6 +133,14 @@ class TestCLIInterface(TestCase):
'-b 10.0.0.1',
['tcp:port=8000:interface=10.0.0.1']
)
self.checkCLI(
'-b 200a::1',
['tcp:port=8000:interface=200a\:\:1']
)
self.checkCLI(
'-b [200a::1]',
['tcp:port=8000:interface=200a\:\:1']
)
self.checkCLI(
'-p 8080 -b example.com',
['tcp:port=8080:interface=example.com']