diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2009-05-08 23:19:47 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2009-05-08 23:19:47 (GMT) |
commit | 2fcd73d7cb9e1e0ce375fcc001c9b7940bb85347 (patch) | |
tree | 1983ee0027623420f64aaae201610d5bf820877e /Lib | |
parent | bb6721474c08d9c941b2fb3f617cfc6956f3a302 (diff) | |
download | cpython-2fcd73d7cb9e1e0ce375fcc001c9b7940bb85347.zip cpython-2fcd73d7cb9e1e0ce375fcc001c9b7940bb85347.tar.gz cpython-2fcd73d7cb9e1e0ce375fcc001c9b7940bb85347.tar.bz2 |
Merged revisions 72489 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r72489 | gregory.p.smith | 2009-05-08 16:16:47 -0700 (Fri, 08 May 2009) | 3 lines
Fix an off by one error on negative indexs to __getitem__
http://code.google.com/p/ipaddr-py/issues/detail?id=15
........
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ipaddr.py | 1 | ||||
-rwxr-xr-x | Lib/test/test_ipaddr.py | 11 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Lib/ipaddr.py b/Lib/ipaddr.py index e0966c6..ef61f85 100644 --- a/Lib/ipaddr.py +++ b/Lib/ipaddr.py @@ -209,6 +209,7 @@ class BaseIP(object): raise IndexError return self._string_from_ip_int(self.network + n) else: + n += 1 if self.broadcast + n < self.network: raise IndexError return self._string_from_ip_int(self.broadcast + n) diff --git a/Lib/test/test_ipaddr.py b/Lib/test/test_ipaddr.py index b0fda04..afa8da3 100755 --- a/Lib/test/test_ipaddr.py +++ b/Lib/test/test_ipaddr.py @@ -274,6 +274,17 @@ class IpaddrUnitTest(unittest.TestCase): self.assertEqual(self.ipv6[5], '2001:658:22a:cafe::5') + def test_getitem(self): + # http://code.google.com/p/ipaddr-py/issues/detail?id=15 + addr = ipaddr.IPv4('172.31.255.128/255.255.255.240') + self.assertEqual(28, addr.prefixlen) + addr_list = list(addr) + self.assertEqual('172.31.255.128', addr_list[0]) + self.assertEqual('172.31.255.128', addr[0]) + self.assertEqual('172.31.255.143', addr_list[-1]) + self.assertEqual('172.31.255.143', addr[-1]) + self.assertEqual(addr_list[-1], addr[-1]) + def test_equals(self): self.assertTrue(self.ipv4 == ipaddr.IPv4('1.2.3.4/24')) self.assertFalse(self.ipv4 == ipaddr.IPv4('1.2.3.4/23')) |