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()
def test_get_handler(self): handler = get_handler() self.assertTrue(isinstance(handler, handlers.ContentHandler))
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)
def test_get_wrong_handler(self): with self.assertRaises(ValueError): get_handler('foo/bar')
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)