match all records that have any args in any key/field that also match
        key/value requirements specified in kwargs
347455
def search(self, *args, **kwargs):
        """"""
        ret = []
        for record in Handler.ALL_VERS_DATA.values():
            matchArgs = list(kwargs.keys())
            for k,v in iteritems(kwargs): # restrict records based on key-value match requirement
                try:
                    if record[k] != v: break # a non-matching requirement means this record doesn't match
                except: break # record doesn't have required key 'k'
                matchArgs.remove(k)
            if matchArgs: continue # didn't match all required kwargs
            matchArgs = list(args)
            for k,v in iteritems(record): # find any record with a <value> in it
                if k in matchArgs: matchArgs.remove(k)
                if v in matchArgs: matchArgs.remove(v)
            if matchArgs: continue # didn't match all required args
            ret.append(record)
        return ret
39809
def _where(self, **kwargs):
        ''''''
        out = self
        for k,v in kwargs.items():
            out = out.where(k, lambda i:i==v)
        return out
427783
def get_field_kwargs(field_name, model_field):
    
    kwargs = {}

    # The following will only be used by ModelField classes.
    # Gets removed for everything else.
    kwargs['model_field'] = model_field

    if hasattr(model_field, 'verbose_name') and needs_label(model_field, field_name):
        kwargs['label'] = capfirst(model_field.verbose_name)

    if hasattr(model_field, 'help_text'):
        kwargs['help_text'] = model_field.help_text

    if isinstance(model_field, me_fields.DecimalField):
        precision = model_field.precision
        max_value = getattr(model_field, 'max_value', None)
        if max_value is not None:
            max_length = len(str(max_value)) + precision
        else:
            max_length = 65536
        kwargs['decimal_places'] = precision
        kwargs['max_digits'] = max_length

    if isinstance(model_field, me_fields.GeoJsonBaseField):
        kwargs['geo_type'] = model_field._type

    if isinstance(model_field, me_fields.SequenceField) or model_field.primary_key or model_field.db_field == '_id':
        # If this field is read-only, then return early.
        # Further keyword arguments are not valid.
        kwargs['read_only'] = True
        return kwargs

    if model_field.default and not isinstance(model_field, me_fields.ComplexBaseField):
        kwargs['default'] = model_field.default

    if model_field.null:
        kwargs['allow_null'] = True

    if model_field.null and isinstance(model_field, me_fields.StringField):
        kwargs['allow_blank'] = True

    if 'default' not in kwargs:
        kwargs['required'] = model_field.required

        # handle special cases - compound fields: mongoengine.ListField/DictField
        if kwargs['required'] is True:
            if isinstance(model_field, me_fields.ListField) or isinstance(model_field, me_fields.DictField):
                kwargs['allow_empty'] = False

    if model_field.choices:
        # If this model field contains choices, then return early.
        # Further keyword arguments are not valid.
        kwargs['choices'] = model_field.choices
        return kwargs

    if isinstance(model_field, me_fields.StringField):
        if model_field.regex:
            kwargs['regex'] = model_field.regex

    max_length = getattr(model_field, 'max_length', None)
    if max_length is not None and isinstance(model_field, me_fields.StringField):
        kwargs['max_length'] = max_length

    min_length = getattr(model_field, 'min_length', None)
    if min_length is not None and isinstance(model_field, me_fields.StringField):
        kwargs['min_length'] = min_length

    max_value = getattr(model_field, 'max_value', None)
    if max_value is not None and isinstance(model_field, NUMERIC_FIELD_TYPES):
        kwargs['max_value'] = max_value

    min_value = getattr(model_field, 'min_value', None)
    if min_value is not None and isinstance(model_field, NUMERIC_FIELD_TYPES):
        kwargs['min_value'] = min_value

    return kwargs
542777
def build_filter_from_kwargs(self, **kwargs):
        """"""
        query = None
        for path_to_convert, value in kwargs.items():

            path_parts = path_to_convert.split('__')
            lookup_class = None
            try:
                # We check if the path ends with something such as __gte, __lte...
                lookup_class = lookups.registry[path_parts[-1]]
                path_to_convert = '__'.join(path_parts[:-1])
            except KeyError:
                pass
            path = lookup_to_path(path_to_convert)

            if lookup_class:
                q = QueryNode(path, lookup=lookup_class(value))
            else:
                q = path == value

            if query:
                query = query & q
            else:
                query = q
        return query
1033914
def check_arguments(self, **kwargs):
        
        for key in kwargs:
            if key in self._rules:
                for val in kwargs[key]:
                    self._rules[key](val)
            else:
                raise LookupError("Rule for {} does not exist. Make sure the rule starts with 'rule_'".format(key))
764614
def aggregate(self, kwargs):
        ''''''
        meta = self._meta
        fields = meta.dfields
        field_lookups = {}
        for name, value in iteritems(kwargs):
            bits = name.split(JSPLITTER)
            field_name = bits.pop(0)
            if field_name not in fields:
                raise QuerySetError('Could not filter on model "{0}".\
 Field "{1}" does not exist.'.format(meta, field_name))
            field = fields[field_name]
            attname = field.attname
            lookup = None
            if bits:
                bits = [n.lower() for n in bits]
                if bits[-1] == 'in':
                    bits.pop()
                elif bits[-1] in range_lookups:
                    lookup = bits.pop()
                remaining = JSPLITTER.join(bits)
                if lookup:  # this is a range lookup
                    attname, nested = field.get_lookup(remaining,
                                                       QuerySetError)
                    lookups = get_lookups(attname, field_lookups)
                    lookups.append(lookup_value(lookup, (value, nested)))
                    continue
                elif remaining:   # Not a range lookup, must be a nested filter
                    value = field.filter(self.session, remaining, value)
            lookups = get_lookups(attname, field_lookups)
            # If we are here the field must be an index
            if not field.index:
                raise QuerySetError("%s %s is not an index. Cannot query." %
                                    (field.__class__.__name__, field_name))
            if not iterable(value):
                value = (value,)
            for v in value:
                if isinstance(v, Q):
                    v = lookup_value('set', v.construct())
                else:
                    v = lookup_value('value', field.serialise(v, lookup))
                lookups.append(v)
        #
        return [queryset(self, name=name, underlying=field_lookups[name])
                for name in sorted(field_lookups)]
1023275
def filter(self, *args, **kwargs):
		""""""
		if 'pk' in kwargs or 'id' in kwargs:
			return self.all_with_deleted().filter(*args, **kwargs)
		return self.get_query_set().filter(*args, **kwargs)
767682
def build_kwargs(self):
        
        keys, self.keys = self.keys[:MAX_GET_BATCH], self.keys[MAX_GET_BATCH:]
        query = {'ConsistentRead': self.consistent}
        if self.attributes is not None:
            query['ProjectionExpression'] = self.attributes
        if self.alias:
            query['ExpressionAttributeNames'] = self.alias
        query['Keys'] = keys
        return {
            'RequestItems': {
                self.tablename: query,
            },
            'ReturnConsumedCapacity': self.return_capacity,
        }
206388
def _preprocess_params(cls, kwargs):
        
        # kwargs.pop('csrf_token', None)
        for attr, val in kwargs.items():
            if cls.is_the_primary_key(attr) and cls._prevent_primary_key_initialization_:
                del kwargs[attr]
                continue
            if val == "":
                # Making an assumption that there is no good usecase
                # for setting an empty string. This will help prevent
                # cases where empty string is sent because of client
                # not clearing form fields to null
                kwargs[attr] = None
                continue
            if attr in class_mapper(cls).relationships and attr not in cls._no_overwrite_:
                rel = class_mapper(cls).relationships[attr]
                if rel.uselist:
                    if isinstance(val, list):
                        if all(isinstance(v, dict) for v in val):
                            rel_cls = cls.mapped_rel_class(attr)
                            kwargs[attr] = rel_cls.update_or_new_all(
                                list_of_kwargs=val, keys=[rel_cls.primary_key_name()])
                    elif isinstance(val, dict):
                        rel_cls = cls.mapped_rel_class(attr)
                        mapping_col = rel.collection_class().keyfunc.name
                        list_of_kwargs = [merge(v, {mapping_col: k}) for k, v in val.items()]
                        kwargs[attr] = {getattr(obj, mapping_col): obj for obj in rel_cls.update_or_new_all(
                            list_of_kwargs=list_of_kwargs, keys=[rel_cls.primary_key_name()])}
                elif isinstance(val, dict):
                    rel_cls = cls.mapped_rel_class(attr)
                    kwargs[attr] = rel_cls.update_or_new(
                        **merge(val, {'keys': [rel_cls.primary_key_name()]}))
        return kwargs
176504
def get_nested_relation_kwargs(field_name, relation_info):
    
    kwargs = get_relation_kwargs(field_name, relation_info)
    kwargs.pop('queryset')
    kwargs.pop('required')
    kwargs['read_only'] = True
    return kwargs
183881
def queryjoin(argdict=dict(), **kwargs):
    
    if kwargs: argdict.update(kwargs)
    
    if issubclass(type(argdict), dict):                    
        args = ["{}={}".format(k, v) for k, v in argdict.items() if v != None]
    return "&".join(args)
335489
def with_known_args(self, **kwargs):
    """"""
    argspec = inspect.getargspec(self.func)
    stored = {}
    for key, arg in six.iteritems(kwargs):
      if key in argspec.args or argspec.keywords:
        stored[key] = arg
    if stored:
      return self.with_args(**stored)
    return self
19241
def include_extra_kwargs(self, kwargs, extra_kwargs):
        
        if extra_kwargs.get('read_only', False):
            for attr in [
                'required', 'default', 'allow_blank', 'allow_null',
                'min_length', 'max_length', 'min_value', 'max_value',
                'validators', 'queryset'
            ]:
                kwargs.pop(attr, None)

        if extra_kwargs.get('default') and kwargs.get('required') is False:
            kwargs.pop('required')

        if extra_kwargs.get('read_only', kwargs.get('read_only', False)):
            extra_kwargs.pop('required', None)  # Read only fields should always omit the 'required' argument.

        kwargs.update(extra_kwargs)

        return kwargs
1223435
def _check_for_invalid_keys(fname, kwargs, compat_args):
    
    # set(dict) --> set of the dictionary's keys
    diff = set(kwargs) - set(compat_args)

    if diff:
        bad_arg = list(diff)[0]
        raise TypeError(("{fname}() got an unexpected "
                         "keyword argument '{arg}'".
                         format(fname=fname, arg=bad_arg)))
675207
def match_function(self, args, kwargs, match_args=(), star_arg=None, kwd_args=(), dubstar_arg=None):
        """"""
        self.match_in_args_kwargs(match_args, args, kwargs, allow_star_args=star_arg is not None)
        if star_arg is not None:
            self.match(star_arg, args + "[" + str(len(match_args)) + ":]")
        self.match_in_kwargs(kwd_args, kwargs)
        with self.down_a_level():
            if dubstar_arg is None:
                self.add_check("not " + kwargs)
            else:
                self.match(dubstar_arg, kwargs)
1324048
def get_relation_kwargs(field_name, relation_info):
    
    model_field, related_model, to_many, to_field, has_through_model = relation_info
    kwargs = {
        'queryset': related_model._default_manager,
        'view_name': get_detail_view_name(related_model)
    }

    if to_many:
        kwargs['many'] = True

    if to_field:
        kwargs['to_field'] = to_field

    if has_through_model:
        kwargs['read_only'] = True
        kwargs.pop('queryset', None)

    if model_field:
        if model_field.verbose_name and needs_label(model_field, field_name):
            kwargs['label'] = capfirst(model_field.verbose_name)
        help_text = model_field.help_text
        if help_text:
            kwargs['help_text'] = help_text
        if not model_field.editable:
            kwargs['read_only'] = True
            kwargs.pop('queryset', None)
        if kwargs.get('read_only', False):
            # If this field is read-only, then return early.
            # No further keyword arguments are valid.
            return kwargs

        if model_field.has_default() or model_field.blank or model_field.null:
            kwargs['required'] = False
        if model_field.null:
            kwargs['allow_null'] = True
        if model_field.validators:
            kwargs['validators'] = model_field.validators
        if getattr(model_field, 'unique', False):
            validator = UniqueValidator(queryset=model_field.model._default_manager)
            kwargs['validators'] = kwargs.get('validators', []) + [validator]
        if to_many and not model_field.blank:
            kwargs['allow_empty'] = False

    return kwargs
397821
function validate(args, required) {
    var result = {
      error: false,
      message: 'No errors'
    }

    // ensure required properties were passed in the arguments hash
    if (required) {
      var keys = _.keys(args);
      required.forEach(function(field) {
        if(!_.contains(keys, field)) {
          result.error = true;
          result.message = 'The following values must be passed: ' + required.join(', ');
        }
      })
    }

    return result;

  }