rest_framework.utils.mediatypes

Handling of media types, as found in HTTP Content-Type and Accept headers.

See https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7

Module Contents

media_type_matches(lhs, rhs)

Returns True if the media type in the first argument <= the media type in the second argument. The media types are strings as described by the HTTP spec.

Valid media type strings include:

‘application/json; indent=4’ ‘application/json’ ‘text/’ ‘/*

order_by_precedence(media_type_lst)

Returns a list of sets of media type strings, ordered by precedence. Precedence is determined by how specific a media type is:

3. ‘type/subtype; param=val’ 2. ‘type/subtype’ 1. ‘type/’ 0. ‘/*

class _MediaType(media_type_str)

Bases:object

precedence

Return a precedence level from 0-3 for the media type given how specific it is.

match(self, other)

Return true if this MediaType satisfies the given MediaType.

__str__(self)