Package openid :: Package yadis :: Module accept
[frames] | no frames]

Module accept

source code

Functions for generating and parsing HTTP Accept: headers for supporting server-directed content negotiation.

Functions
 
generateAcceptHeader(*elements)
Generate an accept header value
source code
 
parseAcceptHeader(value)
Parse an accept header, ignoring any accept-extensions
source code
 
matchTypes(accept_types, have_types)
Given the result of parsing an Accept: header, and the available MIME types, return the acceptable types with their quality markdowns.
source code
 
getAcceptable(accept_header, have_types)
Parse the accept header and return a list of available types in preferred order.
source code
Function Details

generateAcceptHeader(*elements)

source code 

Generate an accept header value

[str or (str, float)] -> str

parseAcceptHeader(value)

source code 

Parse an accept header, ignoring any accept-extensions

returns a list of tuples containing main MIME type, MIME subtype, and quality markdown.

str -> [(str, str, float)]

matchTypes(accept_types, have_types)

source code 

Given the result of parsing an Accept: header, and the available MIME types, return the acceptable types with their quality markdowns.

For example:

>>> acceptable = parseAcceptHeader('text/html, text/plain; q=0.5')
>>> matchTypes(acceptable, ['text/plain', 'text/html', 'image/jpeg'])
[('text/html', 1.0), ('text/plain', 0.5)]

Type signature: ([(str, str, float)], [str]) -> [(str, float)]

getAcceptable(accept_header, have_types)

source code 

Parse the accept header and return a list of available types in preferred order. If a type is unacceptable, it will not be in the resulting list.

This is a convenience wrapper around matchTypes and parseAcceptHeader.

(str, [str]) -> [str]