Legacy filter for determining if a given dict is present.
160414
def is_sub_dict(sub_dict, dictionary):
    """"""
    for key in sub_dict.keys():
        if key not in dictionary:
            return False
        if (type(sub_dict[key]) is not dict) and (sub_dict[key] != dictionary[key]):
            return False
        if (type(sub_dict[key]) is dict) and (not is_sub_dict(sub_dict[key], dictionary[key])):
            return False
    return True
1311528
def _validate_filter(self, keys, filterset_class):
        
        for k in keys:
            if ((not filterset_class) or (k not in filterset_class.base_filters)):
                raise ValidationError("invalid filter[{}]".format(k))
630647
def check(cls, dic):
        
        res = {}
        for name, text in dic.items():
            try:
                p = getattr(cls, name)
            except AttributeError:
                logging.warning('Ignored unknown parameter %s', name)
            else:
                res[name] = p.validator(text)
        return res
1235279
def winnow_by_keys(dct, keys=None, filter_func=None):
    """"""
    has = {}
    has_not = {}

    for key in dct:
        key_passes_check = False
        if keys is not None:
            key_passes_check = key in keys
        elif filter_func is not None:
            key_passes_check = filter_func(key)

        if key_passes_check:
            has[key] = dct[key]
        else:
            has_not[key] = dct[key]

    return WinnowedResult(has, has_not)
443912
def filter(cls, iterable, cond, *a, **kw):
    

    return cls(x for x in iterable if cond(x, *a, **kw))
397425
def dict_filter(d, exclude=[]):
    

    if isinstance(d, list):
        ret = []
        for e in d:
            ret.append(dict_filter(e, exclude))
        return ret
    elif isinstance(d, dict):
        ret = {}
        for k, v in d.items():
            if isinstance(k, builtin_str):
                k = str(k)

            assert isinstance(k, str)
            if k in exclude:
                continue
            ret[k] = dict_filter(v, exclude)
        return ret

    return d
381016
def filter_by(lookup_dict,
              lookup,
              traverse,
              merge=None,
              default='default',
              base=None):
    '''
    
    '''
    ret = None
    # Default value would be an empty list if lookup not found
    val = traverse_dict_and_list(traverse, lookup, [])

    # Iterate over the list of values to match against patterns in the
    # lookup_dict keys
    for each in val if isinstance(val, list) else [val]:
        for key in lookup_dict:
            test_key = key if isinstance(key, six.string_types) \
                else six.text_type(key)
            test_each = each if isinstance(each, six.string_types) \
                else six.text_type(each)
            if fnmatch.fnmatchcase(test_each, test_key):
                ret = lookup_dict[key]
                break
        if ret is not None:
            break

    if ret is None:
        ret = lookup_dict.get(default, None)

    if base and base in lookup_dict:
        base_values = lookup_dict[base]
        if ret is None:
            ret = base_values

        elif isinstance(base_values, Mapping):
            if not isinstance(ret, Mapping):
                raise SaltException(
                    'filter_by default and look-up values must both be '
                    'dictionaries.')
            ret = salt.utils.dictupdate.update(copy.deepcopy(base_values), ret)

    if merge:
        if not isinstance(merge, Mapping):
            raise SaltException(
                'filter_by merge argument must be a dictionary.')

        if ret is None:
            ret = merge
        else:
            salt.utils.dictupdate.update(ret, copy.deepcopy(merge))

    return ret
1329667
def clean_dict(d, test=lambda v: v):
    
    return {k: v for k, v in d.items() if test(v)}
1309491
def filter_none(data: Dict[str, Any],
                keys: OptKeys = None) -> Dict[str, Any]:
    

    def limited_filter(k: str, v: Any) -> bool:
        return k not in keys or v is not None  # type: ignore

    def full_filter(k: str, v: Any) -> bool:
        return v is not None

    f = limited_filter if keys is not None else full_filter
    return {k: v for k, v in data.items() if f(k, v)}
207207
def filterkeys(predicate, dict_):
    
    predicate = bool if predicate is None else ensure_callable(predicate)
    ensure_mapping(dict_)
    return dict_.__class__((k, v) for k, v in iteritems(dict_) if predicate(k))
386749
def is_api_filter(self, filter_field):
        """"""
        if self.filter_type == 'server':
            for choice in self.filter_choices:
                if (choice[0] == filter_field and len(choice) > 2 and
                        choice[2]):
                    return True
        return False
784026
def filter(self, **kwargs):
        """"""
        assert not self._primary_keys
        self.queryset = self.queryset.filter(**kwargs)
        return self
804720
def filteritems(predicate, dict_):
    
    predicate = all if predicate is None else ensure_callable(predicate)
    ensure_mapping(dict_)
    return dict_.__class__(ifilter(predicate, iteritems(dict_)))
229041
def _filter_keys(d: dict, keys: set) -> dict:
        
        return {key: d[key] for key in keys if key in d}
977228
def update_filter_dict(d, user, status):
    
    if user is not None:
        if not user.id:
            return None
        d['user'] = user
    if status is not None:
        d['status'] = status
1090394
def clean_query_Dict(cls, query_Dict):
    
    return {k: v for k, v in query_Dict.items() if v}
676693
def dict_filter(*args, **kwargs):
    
    result = {}
    for arg in itertools.chain(args, (kwargs,)):
        dict_filter_update(result, arg)
    return result