mirror of
https://github.com/python/cpython.git
synced 2025-10-15 03:10:29 +00:00
bpo-32221: makeipaddr(): remove interface part + speedup (GH-5449) (#5449)
This commit is contained in:
parent
3c34aad4e7
commit
7766b96ab8
4 changed files with 116 additions and 28 deletions
|
@ -1594,6 +1594,72 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
with socket.socket(socket.AF_INET6, socket.SOCK_STREAM) as s:
|
||||
self.assertRaises(OverflowError, s.bind, (support.HOSTv6, 0, -10))
|
||||
|
||||
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
|
||||
def test_getaddrinfo_ipv6_basic(self):
|
||||
((*_, sockaddr),) = socket.getaddrinfo(
|
||||
'ff02::1de:c0:face:8D', # Note capital letter `D`.
|
||||
1234, socket.AF_INET6,
|
||||
socket.SOCK_DGRAM,
|
||||
socket.IPPROTO_UDP
|
||||
)
|
||||
self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, 0))
|
||||
|
||||
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
|
||||
@unittest.skipUnless(
|
||||
hasattr(socket, 'if_nameindex'),
|
||||
'if_nameindex is not supported')
|
||||
def test_getaddrinfo_ipv6_scopeid_symbolic(self):
|
||||
# Just pick up any network interface (Linux, Mac OS X)
|
||||
(ifindex, test_interface) = socket.if_nameindex()[0]
|
||||
((*_, sockaddr),) = socket.getaddrinfo(
|
||||
'ff02::1de:c0:face:8D%' + test_interface,
|
||||
1234, socket.AF_INET6,
|
||||
socket.SOCK_DGRAM,
|
||||
socket.IPPROTO_UDP
|
||||
)
|
||||
# Note missing interface name part in IPv6 address
|
||||
self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, ifindex))
|
||||
|
||||
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
|
||||
@unittest.skipUnless(
|
||||
sys.platform == 'win32',
|
||||
'Numeric scope id does not work or undocumented')
|
||||
def test_getaddrinfo_ipv6_scopeid_numeric(self):
|
||||
# Also works on Linux and Mac OS X, but is not documented (?)
|
||||
# Windows, Linux and Max OS X allow nonexistent interface numbers here.
|
||||
ifindex = 42
|
||||
((*_, sockaddr),) = socket.getaddrinfo(
|
||||
'ff02::1de:c0:face:8D%' + str(ifindex),
|
||||
1234, socket.AF_INET6,
|
||||
socket.SOCK_DGRAM,
|
||||
socket.IPPROTO_UDP
|
||||
)
|
||||
# Note missing interface name part in IPv6 address
|
||||
self.assertEqual(sockaddr, ('ff02::1de:c0:face:8d', 1234, 0, ifindex))
|
||||
|
||||
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
|
||||
@unittest.skipUnless(
|
||||
hasattr(socket, 'if_nameindex'),
|
||||
'if_nameindex is not supported')
|
||||
def test_getnameinfo_ipv6_scopeid_symbolic(self):
|
||||
# Just pick up any network interface.
|
||||
(ifindex, test_interface) = socket.if_nameindex()[0]
|
||||
sockaddr = ('ff02::1de:c0:face:8D', 1234, 0, ifindex) # Note capital letter `D`.
|
||||
nameinfo = socket.getnameinfo(sockaddr, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)
|
||||
self.assertEqual(nameinfo, ('ff02::1de:c0:face:8d%' + test_interface, '1234'))
|
||||
|
||||
@unittest.skipUnless(support.IPV6_ENABLED, 'IPv6 required for this test.')
|
||||
@unittest.skipUnless(
|
||||
sys.platform == 'win32',
|
||||
'Numeric scope id does not work or undocumented')
|
||||
def test_getnameinfo_ipv6_scopeid_numeric(self):
|
||||
# Also works on Linux (undocumented), but does not work on Mac OS X
|
||||
# Windows and Linux allow nonexistent interface numbers here.
|
||||
ifindex = 42
|
||||
sockaddr = ('ff02::1de:c0:face:8D', 1234, 0, ifindex) # Note capital letter `D`.
|
||||
nameinfo = socket.getnameinfo(sockaddr, socket.NI_NUMERICHOST | socket.NI_NUMERICSERV)
|
||||
self.assertEqual(nameinfo, ('ff02::1de:c0:face:8d%' + str(ifindex), '1234'))
|
||||
|
||||
def test_str_for_enums(self):
|
||||
# Make sure that the AF_* and SOCK_* constants have enum-like string
|
||||
# reprs.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue