Пример #1
0
def validate_accept(produced_content_types: Iterable,
                    accept_headers: MIMEAccept):
    if not len(accept_headers):
        accept_headers = MIMEAccept([('*/*', 1)])

    # Flask does not like empty content types, but we use them.
    content_type = accept_headers.best_match(
        filter(lambda x: x != '', produced_content_types))
    if content_type is None:
        if '*/*' in accept_headers and '' in produced_content_types:
            return ''
        raise NotAcceptableError(
            description=
            'This endpoint only returns one of the following content types: %s'
            % ', '.join(produced_content_types))
    return content_type
Пример #2
0
 def test_mime_accept(self, values, matches, default, expect):
     accept = MIMEAccept(values)
     match = accept.best_match(matches, default=default)
     assert match == expect