summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shields <mshields@google.com>2015-08-17 18:21:25 -0700
committerMichael Shields <mshields@google.com>2015-08-17 18:21:25 -0700
commit6504b47a02739e853043f0a184f3c39462293e5c (patch)
tree203b2fde3cba7eaa6b4c8b8a0450010239abdb49
parentd74a85c44d99ac7fc02638a1c2066ac08ed22b15 (diff)
parentd5dcb84890b90e0eb95688525586e82ec9bcb361 (diff)
downloadipaddr-py-6504b47a02739e853043f0a184f3c39462293e5c.tar.gz
Merge branch 'alexf101-patch-1'
-rw-r--r--ipaddr.py11
1 files changed, 7 insertions, 4 deletions
diff --git a/ipaddr.py b/ipaddr.py
index 33eb405..c30f298 100644
--- a/ipaddr.py
+++ b/ipaddr.py
@@ -156,16 +156,19 @@ def _find_address_range(addresses):
addresses: a list of IPv4 or IPv6 addresses.
Returns:
- A tuple containing the first and last IP addresses in the sequence.
+ A tuple containing the first and last IP addresses in the sequence,
+ and the index of the last IP address in the sequence.
"""
first = last = addresses[0]
+ last_index = 0
for ip in addresses[1:]:
if ip._ip == last._ip + 1:
last = ip
+ last_index += 1
else:
break
- return (first, last)
+ return (first, last, last_index)
def _get_prefix_length(number1, number2, bits):
"""Get the number of leading bits that are same for two numbers.
@@ -358,8 +361,8 @@ def collapse_address_list(addresses):
nets = sorted(set(nets))
while i < len(ips):
- (first, last) = _find_address_range(ips[i:])
- i = ips.index(last) + 1
+ (first, last, last_index) = _find_address_range(ips[i:])
+ i += last_index + 1
addrs.extend(summarize_address_range(first, last))
return _collapse_address_list_recursive(sorted(