#NEWLINE# def _collapse_addresses_internal( addresses ) : #NEWLINE# #INDENT# "Loops through the addresses, collapsing concurrent netblocks.\n\n    Example:\n\n        ip1 = IPv4Network('192.0.2.0/26')\n        ip2 = IPv4Network('192.0.2.64/26')\n        ip3 = IPv4Network('192.0.2.128/26')\n        ip4 = IPv4Network('192.0.2.192/26')\n\n        _collapse_addresses_internal([ip1, ip2, ip3, ip4]) ->\n          [IPv4Network('192.0.2.0/24')]\n\n        This shouldn't be called directly; it is called via\n          collapse_addresses([]).\n\n    Args:\n        addresses: A list of IPv4Network's or IPv6Network's\n\n    Returns:\n        A list of IPv4Network's or IPv6Network's depending on what we were\n        passed.\n\n    " #NEWLINE# to_merge = list ( addresses ) #NEWLINE# subnets = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# while to_merge : #NEWLINE# #INDENT# net = to_merge . pop ( ) #NEWLINE# supernet = net . supernet ( ) #NEWLINE# existing = subnets . get ( supernet ) #NEWLINE# if ( existing is None ) : #NEWLINE# #INDENT# subnets [ supernet ] = net #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( existing != net ) : #NEWLINE# #INDENT# del subnets [ supernet ] #NEWLINE# to_merge . append ( supernet ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# last = None #NEWLINE# for net in sorted ( subnets . values ( ) ) : #NEWLINE# #INDENT# if ( last is not None ) : #NEWLINE# #INDENT# if ( last . broadcast_address >= net . broadcast_address ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# #UNINDENT# ( yield addresses ) #NEWLINE# last = net