Skip to content

Commit 4766cb7

Browse files
committed
Avoid OverflowError with large ranges
Use `IpRange.__len__()` directly rather than calling `len(IpRange())` when computing the length of an IpRangeList. This won't stop OverflowErrors in calling code such as `len(IpRangeList('fe80::/10'))`, but it will provide a method to work around the overflow by direct use of `IpRangeList.__len__()`. Issue: #12
1 parent f8c4fc6 commit 4766cb7

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

iptools/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ def __len__(self):
219219
2
220220
>>> len(IpRange('127/22'))
221221
1024
222+
>>> IpRange('fe80::/10').__len__()
223+
332306998946228968225951765070086144L
222224
"""
223225
return self._len
224226
#end __len__
@@ -510,8 +512,10 @@ def __len__(self):
510512
256
511513
>>> len(IpRangeList('192.168.0.0/22'))
512514
1024
515+
>>> IpRangeList('fe80::/10').__len__()
516+
332306998946228968225951765070086144L
513517
"""
514-
return sum([len(r) for r in self.ips])
518+
return sum(r.__len__() for r in self.ips)
515519
#end __len__
516520
#end class IpRangeList
517521

0 commit comments

Comments
 (0)