get_best_mimetype(header_value,
within,
default=None)
| source code |
Iterates through 'header_value' and check if found any match
in 'within'.
When */* is part of header_value if no match has yet be found
during the process and 'default' is None,
the first element of 'within' is returned otehrwise 'default'
>>> from amplee.http_helper import get_best_mimetype
>>> l = ['application/rdf+xml', 'application/atom+xml']
>>> a = 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
>>> get_best_mimetype(a, l)
>>> get_best_mimetype(a, l, 'application/atom+xml')
'application/atom+xml'
>>> a = 'text/xml,application/xml,application/atom+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'
>>> get_best_mimetype(a, l)
'application/atom+xml'
>>> l = ['application/rdf+xml', 'entry']
>>> get_best_mimetype(a, l)
'application/atom+xml'
>>> a = 'text/xml,application/xml,text/html;q=0.9,text/plain;q=0.8,image/png'
>>> get_best_mimetype(a, l) # returns None
>>> a = 'application/xml;q=0.9,application/rdf+xml;q=0.8,application/atom+xml'
>>> l = ['application/rdf+xml', 'entry']
>>> get_best_mimetype(a, l)
'application/atom+xml'
>>> a = 'application/xml;q=0.9,application/rdf+xml;q=0.8,application/atom+xml;q=0.1'
>>> get_best_mimetype(a, l)
'application/rdf+xml'
>>> a = 'application/xml,application/rdf+xml;q=0.8,application/atom+xml'
>>> get_best_mimetype(a, l)
'application/atom+xml'
>>> a = 'application/*'
>>> get_best_mimetype(a, l) # returns None
Keyword arguments:
header_value -- a string of an header such as Accept
within -- a list of mime-types
default -- default value to return when nothing has been found
-
|