class Accept(ImmutableList): (source)
Known subclasses: werkzeug.datastructures.CharsetAccept
, werkzeug.datastructures.LanguageAccept
, werkzeug.datastructures.MIMEAccept
An :class:`Accept` object is just a list subclass for lists of ``(value, quality)`` tuples. It is automatically sorted by specificity and quality. All :class:`Accept` objects work similar to a list but provide extra functionality for working with the data. Containment checks are normalized to the rules of that header: >>> a = CharsetAccept([('ISO-8859-1', 1), ('utf-8', 0.7)]) >>> a.best 'ISO-8859-1' >>> 'iso-8859-1' in a True >>> 'UTF8' in a True >>> 'utf7' in a False To get the quality for an item you can use normal item lookup: >>> print a['utf-8'] 0.7 >>> a['utf7'] 0 .. versionchanged:: 0.5 :class:`Accept` objects are forced immutable now. .. versionchanged:: 1.0.0 :class:`Accept` internal values are no longer ordered alphabetically for equal quality tags. Instead the initial order is preserved.
Method | __contains__ |
Undocumented |
Method | __getitem__ |
Besides index lookup (getting item n) you can also pass it a string to get the quality for the item. If the item is not in the list, the returned quality is ``0``. |
Method | __init__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | best |
Returns the best match from a list of possible matches based on the specificity and quality of the client. If two items have the same quality and specificity, the one is returned that comes first. |
Method | find |
Get the position of an entry or return -1. |
Method | index |
Get the position of an entry or raise :exc:`ValueError`. |
Method | quality |
Returns the quality of the key. |
Method | to |
Convert the header set into an HTTP header string. |
Method | values |
Iterate over all values. |
Instance Variable | provided |
Undocumented |
Property | best |
The best match as value. |
Method | _best |
Undocumented |
Method | _specificity |
Returns a tuple describing the value's specificity. |
Method | _value |
Check if a value matches a given accept item. |
Inherited from ImmutableListMixin
(via ImmutableList
):
Method | __delitem__ |
Undocumented |
Method | __hash__ |
Undocumented |
Method | __iadd__ |
Undocumented |
Method | __imul__ |
Undocumented |
Method | __reduce |
Undocumented |
Method | __setitem__ |
Undocumented |
Method | append |
Undocumented |
Method | extend |
Undocumented |
Method | insert |
Undocumented |
Method | pop |
Undocumented |
Method | remove |
Undocumented |
Method | reverse |
Undocumented |
Method | sort |
Undocumented |
Instance Variable | _hash |
Undocumented |
Besides index lookup (getting item n) you can also pass it a string to get the quality for the item. If the item is not in the list, the returned quality is ``0``.
werkzeug.datastructures.LanguageAccept
Returns the best match from a list of possible matches based on the specificity and quality of the client. If two items have the same quality and specificity, the one is returned that comes first. :param matches: a list of matches to check for :param default: the value that is returned if none match
Get the position of an entry or raise :exc:`ValueError`. :param key: The key to be looked up. .. versionchanged:: 0.5 This used to raise :exc:`IndexError`, which was inconsistent with the list API.
Returns the quality of the key. .. versionadded:: 0.6 In previous versions you had to use the item-lookup syntax (eg: ``obj[key]`` instead of ``obj.quality(key)``)
werkzeug.datastructures.MIMEAccept
Returns a tuple describing the value's specificity.
werkzeug.datastructures.CharsetAccept
, werkzeug.datastructures.LanguageAccept
, werkzeug.datastructures.MIMEAccept
Check if a value matches a given accept item.