Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,15 +1150,15 @@ def next_network(self, next_prefix=None):
((new_netmask._ip & self.network_address._ip) >> bit_shift) + 1
) << bit_shift

try:
return self.__class__(
f"{self._string_from_ip_int(next_ip)}/{next_prefix}"
)
except OverflowError:
if next_ip > self._ALL_ONES:
raise ValueError(
f"out of address space, cannot make another /{next_prefix} "
"network"
) from None
)

return self.__class__(
f"{self._string_from_ip_int(next_ip)}/{next_prefix}"
)


class _BaseConstants:
Expand Down
10 changes: 8 additions & 2 deletions Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1596,9 +1596,15 @@ def testNextNetworkWithBadPrefix(self):

def testNextNetworkOutOfAddressSpace(self):
ipv4 = ipaddress.IPv4Network('255.255.255.0/24')
self.assertRaises(ValueError, ipv4.next_network)
self.assertRaisesRegex(
ValueError,
'out of address space, cannot make another /24 network',
ipv4.next_network)
ipv6 = ipaddress.IPv6Network('ffff:ffff:ffff:ffff:ffff:ffff:ffff:0/112')
self.assertRaises(ValueError, ipv6.next_network)
self.assertRaisesRegex(
ValueError,
'out of address space, cannot make another /112 network',
ipv6.next_network)

def testFancySubnetting(self):
self.assertEqual(sorted(self.ipv4_network.subnets(prefixlen_diff=3)),
Expand Down
Loading