def smallest_matching_cidr(ip, cidrs):
    match = None

    if not hasattr(cidrs, '__iter__'):
        raise TypeError('IP address/subnet sequence expected, not %r!'
            % cidrs)

    ip = IPAddress(ip)
    for cidr in sorted([IPNetwork(cidr) for cidr in cidrs]):
        if ip in cidr:
            match = cidr
        else:
            if match is not None and cidr.network not in match:
                break

    return match
Graph traversal iterator.
dataset/ETHPy150Open drkjam/netaddr/netaddr/ip/__init__.py/smallest_matching_cidr--crossover with--dataset/ETHPy150Open nerdvegas/rez/src/rez/vendor/pygraph/algorithms/traversal.py/traversal