Пример #1
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()
Пример #2
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()
Пример #3
0
 def test_get_handler(self):
     handler = get_handler()
     self.assertTrue(isinstance(handler, handlers.ContentHandler))
Пример #4
0
    def __init__(self, request, response_object, status=200):
        mime_type = get_response_type(request)
        handler = get_handler(mime_type)
        body = handler.marshal(response_object)

        HttpResponseBase.__init__(self, body, mime_type, status, mime_type)
Пример #5
0
 def test_get_wrong_handler(self):
     with self.assertRaises(ValueError):
         get_handler('foo/bar')
Пример #6
0
 def test_get_handler(self):
     handler = get_handler()
     self.assertTrue(isinstance(handler, handlers.ContentHandler))
Пример #7
0
    def __init__(self, request, response_object, status=200):
        mime_type = get_response_type(request)
        handler = get_handler(mime_type)
        body = handler.marshal(response_object)

        HttpResponse.__init__(self, body, mime_type, status, mime_type)