mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-27860: ipaddress: fix Interface missed some attributes (GH-12836)
IPv4Interface and IPv6Interface did not has netmask and hostmask attributes when its argument is bytes or int. This commit extracts method for constructors of Network and Interface, and ensure Interface class always provides them.
This commit is contained in:
parent
74125a60b7
commit
6fa84bd12c
2 changed files with 56 additions and 71 deletions
|
@ -399,7 +399,13 @@ class NetmaskTestMixin_v4(CommonTestMixin_v4):
|
|||
"""Input validation on interfaces and networks is very similar"""
|
||||
|
||||
def test_no_mask(self):
|
||||
self.assertEqual(str(self.factory('1.2.3.4')), '1.2.3.4/32')
|
||||
for address in ('1.2.3.4', 0x01020304, b'\x01\x02\x03\x04'):
|
||||
net = self.factory(address)
|
||||
self.assertEqual(str(net), '1.2.3.4/32')
|
||||
self.assertEqual(str(net.netmask), '255.255.255.255')
|
||||
self.assertEqual(str(net.hostmask), '0.0.0.0')
|
||||
# IPv4Network has prefixlen, but IPv4Interface doesn't.
|
||||
# Should we add it to IPv4Interface too? (bpo-36392)
|
||||
|
||||
def test_split_netmask(self):
|
||||
addr = "1.2.3.4/32/24"
|
||||
|
@ -527,6 +533,15 @@ class NetworkTestCase_v4(BaseTestCase, NetmaskTestMixin_v4):
|
|||
class NetmaskTestMixin_v6(CommonTestMixin_v6):
|
||||
"""Input validation on interfaces and networks is very similar"""
|
||||
|
||||
def test_no_mask(self):
|
||||
for address in ('::1', 1, b'\x00'*15 + b'\x01'):
|
||||
net = self.factory(address)
|
||||
self.assertEqual(str(net), '::1/128')
|
||||
self.assertEqual(str(net.netmask), 'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')
|
||||
self.assertEqual(str(net.hostmask), '::')
|
||||
# IPv6Network has prefixlen, but IPv6Interface doesn't.
|
||||
# Should we add it to IPv4Interface too? (bpo-36392)
|
||||
|
||||
def test_split_netmask(self):
|
||||
addr = "cafe:cafe::/128/190"
|
||||
with self.assertAddressError("Only one '/' permitted in %r" % addr):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue