mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #20508: Improve exception message of IPv{4,6}Network.__getitem__
Patch by Gareth Rees.
This commit is contained in:
parent
24b102e6e8
commit
28dc1186a8
3 changed files with 6 additions and 2 deletions
|
@ -636,12 +636,12 @@ class _BaseNetwork(_IPAddressBase):
|
||||||
broadcast = int(self.broadcast_address)
|
broadcast = int(self.broadcast_address)
|
||||||
if n >= 0:
|
if n >= 0:
|
||||||
if network + n > broadcast:
|
if network + n > broadcast:
|
||||||
raise IndexError
|
raise IndexError('address out of range')
|
||||||
return self._address_class(network + n)
|
return self._address_class(network + n)
|
||||||
else:
|
else:
|
||||||
n += 1
|
n += 1
|
||||||
if broadcast + n < network:
|
if broadcast + n < network:
|
||||||
raise IndexError
|
raise IndexError('address out of range')
|
||||||
return self._address_class(broadcast + n)
|
return self._address_class(broadcast + n)
|
||||||
|
|
||||||
def __lt__(self, other):
|
def __lt__(self, other):
|
||||||
|
|
|
@ -1176,6 +1176,7 @@ class IpaddrUnitTest(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(str(self.ipv6_network[5]),
|
self.assertEqual(str(self.ipv6_network[5]),
|
||||||
'2001:658:22a:cafe::5')
|
'2001:658:22a:cafe::5')
|
||||||
|
self.assertRaises(IndexError, self.ipv6_network.__getitem__, 1 << 64)
|
||||||
|
|
||||||
def testGetitem(self):
|
def testGetitem(self):
|
||||||
# http://code.google.com/p/ipaddr-py/issues/detail?id=15
|
# http://code.google.com/p/ipaddr-py/issues/detail?id=15
|
||||||
|
|
|
@ -38,6 +38,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #20508: Improve exception message of IPv{4,6}Network.__getitem__.
|
||||||
|
Patch by Gareth Rees.
|
||||||
|
|
||||||
- Issue #21386: Implement missing IPv4Address.is_global property. It was
|
- Issue #21386: Implement missing IPv4Address.is_global property. It was
|
||||||
documented since 07a5610bae9d. Initial patch by Roger Luethi.
|
documented since 07a5610bae9d. Initial patch by Roger Luethi.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue