Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(112)

Delta Between Two Patch Sets: ipaddr.py

Issue 67107: collapse_address_list is too slow SVN Base: http://ipaddr-py.googlecode.com/svn/trunk/
Left Patch Set: Treat a list of /32 or /128 Networks as IP addresses so collapse_address_list can summarize them. Created 3 months, 2 weeks ago
Right Patch Set: Fixes for comments on Patch Set 6 Created 3 months, 2 weeks ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # 2 #
3 # Copyright 2007 Google Inc. 3 # Copyright 2007 Google Inc.
4 # Licensed to PSF under a Contributor Agreement. 4 # Licensed to PSF under a Contributor Agreement.
5 # 5 #
6 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License. 7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at 8 # You may obtain a copy of the License at
9 # 9 #
10 # http://www.apache.org/licenses/LICENSE-2.0 10 # http://www.apache.org/licenses/LICENSE-2.0
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 IPTypeError: 242 IPTypeError:
243 If the first and last objects are not IP addresses. 243 If the first and last objects are not IP addresses.
244 If the first and last objects are not the same version. 244 If the first and last objects are not the same version.
245 ValueError: 245 ValueError:
246 If the last object is not greater than the first. 246 If the last object is not greater than the first.
247 If the version is not 4 or 6. 247 If the version is not 4 or 6.
248 248
249 """ 249 """
250 250
251 if not (isinstance(first, BaseIP) and isinstance(last, BaseIP)): 251 if not (isinstance(first, BaseIP) and isinstance(last, BaseIP)):
252 raise IPTypeError("first and last must be IP addresses not networks.") 252 raise IPTypeError("first and last must be IP addresses, not networks")
Peter Moody 2009/08/20 18:21:17 ..." must be IP addresses, not networks"
Matthew Flanagan 2009/08/21 00:55:57 On 2009/08/20 18:21:17, Peter Moody wrote: > ..."
253 if first.version != last.version: 253 if first.version != last.version:
254 raise IPTypeError("IP addresses must be same version") 254 raise IPTypeError("IP addresses must be same version")
255 if first > last: 255 if first > last:
256 raise ValueError("last IP address must be greater than first") 256 raise ValueError("last IP address must be greater than first")
257 257
258 networks = [] 258 networks = []
259 259
260 if first.version == 4: 260 if first.version == 4:
261 ip = IPv4Network 261 ip = IPv4Network
262 elif first.version == 6: 262 elif first.version == 6:
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 346
347 """ 347 """
348 i = 0 348 i = 0
349 addrs = [] 349 addrs = []
350 ips = [] 350 ips = []
351 nets = [] 351 nets = []
352 # split IP addresses and networks 352 # split IP addresses and networks
353 for ip in addresses: 353 for ip in addresses:
354 if isinstance(ip, BaseIP): 354 if isinstance(ip, BaseIP):
355 ips.append(ip) 355 ips.append(ip)
356 elif isinstance(ip, BaseNet): 356 elif ip._prefixlen == ip._max_prefixlen:
Peter Moody 2009/08/20 18:21:17 i think you can skip this elif check and just make
Matthew Flanagan 2009/08/21 00:55:57 On 2009/08/20 18:21:17, Peter Moody wrote: > i thi
357 if ip._prefixlen == ip._max_prefixlen: 357 ips.append(ip.ip)
358 ips.append(ip.ip) 358 else:
359 else: 359 nets.append(ip)
360 nets.append(ip)
361 # sort and dedup 360 # sort and dedup
362 ips = sorted(set(ips)) 361 ips = sorted(set(ips))
363 nets = sorted(set(nets)) 362 nets = sorted(set(nets))
364 363
365 while i < len(ips): 364 while i < len(ips):
366 (first, last) = _find_address_range(ips[i:]) 365 (first, last) = _find_address_range(ips[i:])
367 i = ips.index(last) + 1 366 i = ips.index(last) + 1
368 addrs.extend(summarize_address_range(first, last)) 367 addrs.extend(summarize_address_range(first, last))
369 368
370 return _collapse_address_list_recursive( 369 return _collapse_address_list_recursive(
(...skipping 1422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1793 """ 1792 """
1794 try: 1793 try:
1795 prefixlen = int(prefixlen) 1794 prefixlen = int(prefixlen)
1796 except ValueError: 1795 except ValueError:
1797 return False 1796 return False
1798 return 0 <= prefixlen <= 128 1797 return 0 <= prefixlen <= 128
1799 1798
1800 # backwards compatibility 1799 # backwards compatibility
1801 Subnet = subnet 1800 Subnet = subnet
1802 Supernet = supernet 1801 Supernet = supernet
LEFTRIGHT
« no previous file | ipaddr_test.py » ('j') | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld r497