#NEWLINE# def all_matching_cidrs( ip , cidrs ) : #NEWLINE# #INDENT# '\n    Matches an IP address or subnet against a given sequence of IP addresses\n    and subnets.\n\n    :param ip: a single IP address.\n\n    :param cidrs: a sequence of IP addresses and/or subnets.\n\n    :return: all matching IPAddress and/or IPNetwork objects from the provided\n        sequence, an empty list if there was no match.\n    ' #NEWLINE# matches = [ ] #NEWLINE# if ( not hasattr ( cidrs , '__iter__' ) ) : #NEWLINE# #INDENT# raise TypeError ( ( 'IP address/subnet sequence expected, not %r!' % cidrs ) ) #NEWLINE# #UNINDENT# ip = IPAddress ( ip ) #NEWLINE# for cidr in sorted ( [ IPNetwork ( cidr ) for cidr in cidrs ] ) : #NEWLINE# #INDENT# if ( ip in cidr ) : #NEWLINE# #INDENT# matches . append ( cidr ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( matches and ( cidr . network not in matches [ ( - 1 ) ] ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return matches