Пример #1
0
    def select_parser(self, parsers):
        """
        Determine which parser to use for parsing the request body.
        Returns a two-tuple of (parser, content type).
        """
        content_type_header = request.content_type

        client_media_type = MediaType(content_type_header)
        for parser in parsers:
            server_media_type = MediaType(parser.media_type)
            if server_media_type.satisfies(client_media_type):
                return (parser, client_media_type)

        raise exceptions.UnsupportedMediaType()
Пример #2
0
    def select_parser(self, parsers):
        """
        Determine which parser to use for parsing the request body.
        Returns a two-tuple of (parser, content type).
        """
        content_type_header = request.content_type

        client_media_type = MediaType(content_type_header)
        for parser in parsers:
            server_media_type = MediaType(parser.media_type)
            if server_media_type.satisfies(client_media_type):
                return (parser, client_media_type)

        raise exceptions.UnsupportedMediaType()
 def test_media_type_wildcard_mismatch(self):
     media_type = MediaType('image/*')
     other = MediaType('audio/*')
     self.assertFalse(media_type.satisfies(other))
 def test_media_type_sub_type_mismatch(self):
     media_type = MediaType('image/jpeg')
     other = MediaType('image/png')
     self.assertFalse(media_type.satisfies(other))
 def test_media_type_wildcard_match(self):
     media_type = MediaType('*/*')
     other = MediaType('image/png')
     self.assertTrue(media_type.satisfies(other))
 def test_media_type_includes_params(self):
     media_type = MediaType('application/json')
     other = MediaType('application/json; version=1.0')
     self.assertTrue(media_type.satisfies(other))
 def test_media_type_non_matching_params(self):
     media_type = MediaType('application/json; version=1.0')
     other = MediaType('application/json; version=2.0')
     self.assertFalse(media_type.satisfies(other))
Пример #8
0
 def test_media_type_wildcard_match(self):
     media_type = MediaType('*/*')
     other = MediaType('image/png')
     self.assertTrue(media_type.satisfies(other))
Пример #9
0
 def test_media_type_wildcard_mismatch(self):
     media_type = MediaType('image/*')
     other = MediaType('audio/*')
     self.assertFalse(media_type.satisfies(other))
Пример #10
0
 def test_media_type_sub_type_mismatch(self):
     media_type = MediaType('image/jpeg')
     other = MediaType('image/png')
     self.assertFalse(media_type.satisfies(other))
Пример #11
0
 def test_media_type_non_matching_params(self):
     media_type = MediaType('application/json; version=1.0')
     other = MediaType('application/json; version=2.0')
     self.assertFalse(media_type.satisfies(other))
Пример #12
0
 def test_media_type_includes_params(self):
     media_type = MediaType('application/json')
     other = MediaType('application/json; version=1.0')
     self.assertTrue(media_type.satisfies(other))
Пример #13
0
 def test_media_type_main_type_match(self):
     media_type = MediaType('image/*')
     other = MediaType('image/png')
     assert media_type.satisfies(other)
Пример #14
0
 def test_media_type_matching_params(self):
     media_type = MediaType('application/json; version=1.0')
     other = MediaType('application/json; version=1.0')
     assert media_type.satisfies(other)