'Filter a list of references by filter values.'

@classmethod
def filter_by_attributes(cls, refs, hints):

    def _attr_match(ref_attr, val_attr):
        "Matche    attributes    allowing    for    booleans    as    strings.\n\n                                                We    test    explicitly    for    a    value    that    defines    it    as    'False',\n                                                which    also    means    that    the    existence    of    the    attribute    with\n                                                no    value    implies    'True'\n\n                                                "
        if (type(ref_attr) is bool):
            return (ref_attr == utils.attr_as_boolean(val_attr))
        else:
            return (ref_attr == val_attr)
    def _inexact_attr_match(filter, ref):
        'Apply    an    inexact    filter    to    a    result    dict.\n\n                                                :param    filter:    the    filter    in    question\n                                                :param    ref:    the    dict    to    check\n\n                                                :returns:    True    if    there    is    a    match\n\n                                                '
        comparator = filter['comparator']
        key = filter['name']
        if (key in ref):
            filter_value = filter['value']
            target_value = ref[key]
            if (not filter['case_sensitive']):
                filter_value = filter_value.lower()
                target_value = target_value.lower()
            if (comparator == 'contains'):
                return (filter_value in target_value)
            elif (comparator == 'startswith'):
                return target_value.startswith(filter_value)
            elif (comparator == 'endswith'):
                return target_value.endswith(filter_value)
            else:
                return True
        return False
    for filter in hints.filters:
        if (filter['comparator'] == 'equals'):
            attr = filter['name']
            value = filter['value']
            refs = [r for r in refs if _attr_match(utils.flatten_dict(r).get(attr), value)]
        else:
            refs = [r for r in refs if _inexact_attr_match(filter, r)]
    return refs
