Match serializer by query arg.
4041
def _match_serializers_by_query_arg(self, serializers):
        """"""
        # if the format query argument is present, match the serializer
        arg_name = current_app.config.get('REST_MIMETYPE_QUERY_ARG_NAME')
        if arg_name:
            arg_value = request.args.get(arg_name, None)

            if arg_value is None:
                return None
            # Search for the serializer matching the format
            try:
                return serializers[
                    self.serializers_query_aliases[arg_value]]
            except KeyError:  # either no serializer for this format
                return None

        return None
399225
def get(self, *args, **kwargs):
        
        clone = self.filter(*args, **kwargs)

        if self.query.can_filter():
            clone = clone.order_by()

        num = len(clone)

        if num == 1:
            return clone._result_cache[0]
        if not num:
            raise self.resource.DoesNotExist(
                "%s matching query does not exist. "
                "Lookup parameters were %s" %
                (self.resource._meta.resource_name, kwargs))

        raise self.resource.MultipleObjectsReturned(
            "get() returned more than one %s -- it returned %s! "
            "Lookup parameters were %s" %
            (self.resource._meta.resource_name, num, kwargs))
233082
def get_serializer_in(self, *args, **kwargs):
        
        serializer_class = self.get_serializer_class_in()
        kwargs['context'] = self.get_serializer_context()
        return serializer_class(*args, **kwargs)
870030
def filter_dict(self, query, **kwargs):
        ''' 
        '''
        for name, value in query.items():
            field = name.split(".")[0]
            try:
                getattr(self.type, field)
            except AttributeError:
                raise FieldNotFoundException("Field not found %s" % (field))
        self.query_bypass(query, raw_output=False, **kwargs)
        return self
560529
def parse_querystring(self, req, name, field):
        """"""
        return get_value(req.query_arguments, name, field)
602122
def get_mongo_query_from_arguments(self, reserved_attributes=[]):
        

        query = {}
        for arg in self.request.arguments:
            if arg not in reserved_attributes:
                if len(self.request.arguments.get(arg)) > 1:
                    query["$or"] = []
                    for val in self.request.arguments.get(arg):
                        query["$or"].append({arg: self.get_arg_value_as_type(val)})
                else:
                    query[arg] = self.get_arg_value_as_type(self.request.arguments.get(arg)[0])

        return query
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
1680
def filter_by(self, **kwargs):
        
        query = self._copy()
        for field, value in kwargs.items():
            query.domain.append(
                (field, '=', value)
            )
        return query
391730
def get_facet_serializer(self, *args, **kwargs):
        
        assert "objects" in kwargs, "`objects` is a required argument to `get_facet_serializer()`"

        facet_serializer_class = self.get_facet_serializer_class()
        kwargs["context"] = self.get_serializer_context()
        kwargs["context"].update({
            "objects": kwargs.pop("objects"),
            "facet_query_params_text": self.facet_query_params_text,
        })
        return facet_serializer_class(*args, **kwargs)
690652
def filter_from_url_arg(model_cls, query, arg, query_operator=and_,
                        arg_types=None):
    

    fields = arg.split(',')
    mapper = class_mapper(model_cls)

    if not arg_types:
        arg_types = {}

    exprs = []
    joins = set()
    for expr in fields:
        if expr == "":
            continue

        e_mapper = mapper
        e_model_cls = model_cls

        operator = None
        method = None
        for op in operator_order:
            if op in expr:
                operator = op
                method = operator_to_method[op]
                break

        if operator is None:
            raise Exception('No operator in expression "{0}".'.format(expr))

        (column_names, value) = expr.split(operator)

        column_names = column_names.split('__')
        value = value.strip()

        for column_name in column_names:
            if column_name in arg_types:
                typed_value = arg_types[column_name](value)
            else:
                typed_value = value

            if column_name in e_mapper.relationships:
                joins.add(column_name)
                e_model_cls = e_mapper.attrs[column_name].mapper.class_
                e_mapper = class_mapper(e_model_cls)

        if hasattr(e_model_cls, column_name):
            column = getattr(e_model_cls, column_name)
            exprs.append(getattr(column, method)(typed_value))
        else:
            raise Exception('Invalid property {0} in class {1}.'.format(column_name, e_model_cls))

    return query.join(*joins).filter(query_operator(*exprs))
950114
function serialize(queryParams) {
  return Object.keys(queryParams)
    .filter(key => queryParams[key] !== undefined)
    .map(key => arrayToStr(key, queryParams[key]))
    .join('&');
}
758727
def basic_query(returns):
    """"""
    return compose(
        reusable,
        map_send(parse_request),
        map_yield(prepare_params, snug.prefix_adder(API_PREFIX)),
        map_return(loads(returns)),
        oneyield,
    )
147712
def matches_query(self, key, query):
        
        dumped = query.dump()
        dumped['className'] = query._query_class._class_name
        self._add_condition(key, '$inQuery', dumped)
        return self
1338836
def find(self, target, relation):
        '''  '''
        query = 'select ob1.code from objects as ob1, objects as ob2, relations where relations.dst=ob1.id and relations.name=? and relations.src=ob2.id and ob2.code=?' # src is id not source :/
        for i in self._execute(query, (relation, self.serialize(target))):
            yield self.deserialize(i[0])
679854
def query(cls, *args, **kwargs):
        
        for doc in cls._coll.find(*args, **kwargs):
            yield cls.from_storage(doc)
1291068
def query(self):
        """"""
        if self._query is None:
            query_string = self.environ.get('QUERY_STRING')
            self._query = QueryDict([
                (k.decode('utf-8'), v.decode('utf-8'))
                for k, v in urlparse.parse_qsl(
                    query_string, keep_blank_values=True)
            ])
        return self._query
905762
def validate_query_params(self, request):
        
        # TODO: For jsonapi error object conformance, must set jsonapi errors "parameter" for
        # the ValidationError. This requires extending DRF/DJA Exceptions.
        for qp in request.query_params.keys():
            if not self.query_regex.match(qp):
                raise ValidationError('invalid query parameter: {}'.format(qp))
            if len(request.query_params.getlist(qp)) > 1:
                raise ValidationError(
                    'repeated query parameter not allowed: {}'.format(qp))