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


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/’ ‘/*


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)



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.