#NEWLINE# def _collapse_address_list_recursive( addresses ) : #NEWLINE# #INDENT# "Loops through the addresses, collapsing concurrent netblocks.\n\n    Example:\n\n        ip1 = IPv4Network'1.1.0.0/24')\n        ip2 = IPv4Network'1.1.1.0/24')\n        ip3 = IPv4Network'1.1.2.0/24')\n        ip4 = IPv4Network'1.1.3.0/24')\n        ip5 = IPv4Network'1.1.4.0/24')\n        ip6 = IPv4Network'1.1.0.1/22')\n\n        _collapse_address_list_recursive([ip1, ip2, ip3, ip4, ip5, ip6]) ->\n          [IPv4Network('1.1.0.0/22'), IPv4Network('1.1.4.0/24')]\n\n        This shouldn't be called directly; it is called via\n          collapse_address_list([]).\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# ret_array = [ ] #NEWLINE# optimized = False #NEWLINE# for cur_addr in addresses : #NEWLINE# #INDENT# if ( not addresses ) : #NEWLINE# #INDENT# ret_array . append ( cur_addr ) #NEWLINE# continue #NEWLINE# #UNINDENT# if ( cur_addr in ret_array [ ( - 1 ) ] ) : #NEWLINE# #INDENT# optimized = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( cur_addr == ret_array [ ( - 1 ) ] . supernet ( ) . subnet ( ) [ 1 ] ) : #NEWLINE# #INDENT# ret_array . append ( ret_array . pop ( ) . supernet ( ) ) #NEWLINE# optimized = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# ret_array . append ( cur_addr ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if optimized : #NEWLINE# #INDENT# return _collapse_address_list_recursive ( ret_array ) #NEWLINE# #UNINDENT# return ret_array