werkzeug.Accept
¶
-
class
werkzeug.
Accept
(values=())[source]¶ An
Accept
object is just a list subclass for lists of(value, quality)
tuples. It is automatically sorted by quality.All
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
Changed in version 0.5:
Accept
objects are forced immutable now.
Methods¶
__init__ ([values]) |
|
append (item) |
|
best_match (matches[, default]) |
Returns the best match from a list of possible matches based on the quality of the client. |
count (...) |
|
extend (iterable) |
|
find (key) |
Get the position of an entry or return -1. |
index (key) |
Get the position of an entry or raise ValueError . |
insert (pos, value) |
|
itervalues () |
Iterate over all values. |
pop ([index]) |
|
quality (key) |
Returns the quality of the key. |
remove (item) |
|
reverse () |
|
sort ([cmp, key, reverse]) |
|
to_header () |
Convert the header set into an HTTP header string. |
values (*a, **kw) |
Like itervalues() , but returns a list. |