Exemplo n.º 1
0
def get_response_type(request):
    supported = get_supported()

    header = request.META['HTTP_ACCEPT']
    match = mimeparse.best_match(supported, header)
    if match:
        return match
    else:
        raise NotAcceptable()
Exemplo n.º 2
0
def get_response_type(request):
    supported = get_supported()

    header = request.META['HTTP_ACCEPT']
    match = mimeparse.best_match(supported, header)
    if match:
        return match
    else:
        raise NotAcceptable()
Exemplo n.º 3
0
def parse_dict(request):
    supported = get_supported()

    header = request.META['CONTENT_TYPE']
    mime_type = mimeparse.best_match(supported, header)
    if mime_type:
        handler = get_handler(mime_type)

        try:
            data = handler.unmarshal_dict(request.body)
            assert isinstance(data, dict), "Request body is not a dictionary."
            return data
        except UnmarshalError:
            raise BadRequest()
    else:
        raise UnsupportedMediaType()
Exemplo n.º 4
0
def parse_dict(request):
    supported = get_supported()

    header = request.META['CONTENT_TYPE']
    mime_type = mimeparse.best_match(supported, header)
    if mime_type:
        handler = get_handler(mime_type)

        try:
            data = handler.unmarshal_dict(request.body)
            assert isinstance(data, dict), "Request body is not a dictionary."
            return data
        except UnmarshalError:
            raise BadRequest()
    else:
        raise UnsupportedMediaType()