import itertools
import fnmatch


def ignore_rules_for_url(spider, url):
    """
    Returns a list of ignore rules from the given spider,
    that are relevant to the given URL.
    """
    ignore_rules = getattr(spider, "pa11y_ignore_rules", {}) or {}
    return itertools.chain.from_iterable(
        rule_list
        for url_glob, rule_list
        in ignore_rules.items()
        if fnmatch.fnmatch(url, url_glob)
    )