OpenQuizz
Une application de gestion des contenus pédagogiques
|
Public Member Functions | |
def | __init__ (self, defaults=None) |
def | __getitem__ (self, key, _get_mode=False) |
def | __eq__ (self, other) |
def | __ne__ (self, other) |
def | get (self, key, default=None, type=None, as_bytes=False) |
def | getlist (self, key, type=None, as_bytes=False) |
def | get_all (self, name) |
def | items (self, lower=False) |
def | keys (self, lower=False) |
def | values (self) |
def | extend (self, *args, **kwargs) |
def | __delitem__ (self, key, _index_operation=True) |
def | remove (self, key) |
def | pop (self, key=None, default=_missing) |
def | popitem (self) |
def | __contains__ (self, key) |
def | __iter__ (self) |
def | __len__ (self) |
def | add (self, _key, _value, **kw) |
def | add_header (self, _key, _value, **_kw) |
def | clear (self) |
def | set (self, _key, _value, **kw) |
def | setlist (self, key, values) |
def | setdefault (self, key, default) |
def | setlistdefault (self, key, default) |
def | __setitem__ (self, key, value) |
def | update (self, *args, **kwargs) |
def | to_wsgi_list (self) |
def | copy (self) |
def | __copy__ (self) |
def | __str__ (self) |
def | __repr__ (self) |
Static Public Attributes | |
has_key | |
An object that stores some headers. It has a dict-like interface but is ordered and can store the same keys multiple times. This data structure is useful if you want a nicer way to handle WSGI headers which are stored as tuples in a list. From Werkzeug 0.3 onwards, the :exc:`KeyError` raised by this class is also a subclass of the :class:`~exceptions.BadRequest` HTTP exception and will render a page for a ``400 BAD REQUEST`` if caught in a catch-all for HTTP exceptions. Headers is mostly compatible with the Python :class:`wsgiref.headers.Headers` class, with the exception of `__getitem__`. :mod:`wsgiref` will return `None` for ``headers['missing']``, whereas :class:`Headers` will raise a :class:`KeyError`. To create a new :class:`Headers` object pass it a list or dict of headers which are used as default values. This does not reuse the list passed to the constructor for internal usage. :param defaults: The list of default values for the :class:`Headers`. .. versionchanged:: 0.9 This data structure now stores unicode values similar to how the multi dicts do it. The main difference is that bytes can be set as well which will automatically be latin1 decoded. .. versionchanged:: 0.9 The :meth:`linked` function was removed without replacement as it was an API that does not support the changes to the encoding model.
def __init__ | ( | self, | |
defaults = None |
|||
) |
Reimplemented in EnvironHeaders.
def __contains__ | ( | self, | |
key | |||
) |
Check if a key is present.
def __copy__ | ( | self | ) |
def __delitem__ | ( | self, | |
key, | |||
_index_operation = True |
|||
) |
def __eq__ | ( | self, | |
other | |||
) |
Reimplemented in EnvironHeaders.
def __getitem__ | ( | self, | |
key, | |||
_get_mode = False |
|||
) |
Reimplemented in EnvironHeaders.
def __iter__ | ( | self | ) |
Yield ``(key, value)`` tuples.
Reimplemented in EnvironHeaders.
def __len__ | ( | self | ) |
Reimplemented in EnvironHeaders.
def __ne__ | ( | self, | |
other | |||
) |
def __repr__ | ( | self | ) |
def __setitem__ | ( | self, | |
key, | |||
value | |||
) |
Like :meth:`set` but also supports index/slice based setting.
def __str__ | ( | self | ) |
Returns formatted headers suitable for HTTP transmission.
def add | ( | self, | |
_key, | |||
_value, | |||
** | kw | ||
) |
Add a new header tuple to the list. Keyword arguments can specify additional parameters for the header value, with underscores converted to dashes:: >>> d = Headers() >>> d.add('Content-Type', 'text/plain') >>> d.add('Content-Disposition', 'attachment', filename='foo.png') The keyword argument dumping uses :func:`dump_options_header` behind the scenes. .. versionadded:: 0.4.1 keyword arguments were added for :mod:`wsgiref` compatibility.
def add_header | ( | self, | |
_key, | |||
_value, | |||
** | _kw | ||
) |
Add a new header tuple to the list. An alias for :meth:`add` for compatibility with the :mod:`wsgiref` :meth:`~wsgiref.headers.Headers.add_header` method.
def clear | ( | self | ) |
Clears all headers.
def copy | ( | self | ) |
Reimplemented in EnvironHeaders.
def extend | ( | self, | |
* | args, | ||
** | kwargs | ||
) |
Extend headers in this object with items from another object containing header items as well as keyword arguments. To replace existing keys instead of extending, use :meth:`update` instead. If provided, the first argument can be another :class:`Headers` object, a :class:`MultiDict`, :class:`dict`, or iterable of pairs. .. versionchanged:: 1.0 Support :class:`MultiDict`. Allow passing ``kwargs``.
def get | ( | self, | |
key, | |||
default = None , |
|||
type = None , |
|||
as_bytes = False |
|||
) |
Return the default value if the requested data doesn't exist. If `type` is provided and is a callable it should convert the value, return it or raise a :exc:`ValueError` if that is not possible. In this case the function will return the default as if the value was not found: >>> d = Headers([('Content-Length', '42')]) >>> d.get('Content-Length', type=int) 42 If a headers object is bound you must not add unicode strings because no encoding takes place. .. versionadded:: 0.9 Added support for `as_bytes`. :param key: The key to be looked up. :param default: The default value to be returned if the key can't be looked up. If not further specified `None` is returned. :param type: A callable that is used to cast the value in the :class:`Headers`. If a :exc:`ValueError` is raised by this callable the default value is returned. :param as_bytes: return bytes instead of unicode strings.
def get_all | ( | self, | |
name | |||
) |
Return a list of all the values for the named field. This method is compatible with the :mod:`wsgiref` :meth:`~wsgiref.headers.Headers.get_all` method.
def getlist | ( | self, | |
key, | |||
type = None , |
|||
as_bytes = False |
|||
) |
Return the list of items for a given key. If that key is not in the :class:`Headers`, the return value will be an empty list. Just as :meth:`get` :meth:`getlist` accepts a `type` parameter. All items will be converted with the callable defined there. .. versionadded:: 0.9 Added support for `as_bytes`. :param key: The key to be looked up. :param type: A callable that is used to cast the value in the :class:`Headers`. If a :exc:`ValueError` is raised by this callable the value will be removed from the list. :return: a :class:`list` of all the values for the key. :param as_bytes: return bytes instead of unicode strings.
def items | ( | self, | |
lower = False |
|||
) |
def keys | ( | self, | |
lower = False |
|||
) |
def pop | ( | self, | |
key = None , |
|||
default = _missing |
|||
) |
Removes and returns a key or index. :param key: The key to be popped. If this is an integer the item at that position is removed, if it's a string the value for that key is. If the key is omitted or `None` the last item is removed. :return: an item.
def popitem | ( | self | ) |
Removes a key or index and returns a (key, value) item.
def remove | ( | self, | |
key | |||
) |
Remove a key. :param key: The key to be removed.
def set | ( | self, | |
_key, | |||
_value, | |||
** | kw | ||
) |
Remove all header tuples for `key` and add a new one. The newly added key either appears at the end of the list if there was no entry or replaces the first one. Keyword arguments can specify additional parameters for the header value, with underscores converted to dashes. See :meth:`add` for more information. .. versionchanged:: 0.6.1 :meth:`set` now accepts the same arguments as :meth:`add`. :param key: The key to be inserted. :param value: The value to be inserted.
def setdefault | ( | self, | |
key, | |||
default | |||
) |
Return the first value for the key if it is in the headers, otherwise set the header to the value given by ``default`` and return that. :param key: The header key to get. :param default: The value to set for the key if it is not in the headers.
def setlist | ( | self, | |
key, | |||
values | |||
) |
Remove any existing values for a header and add new ones. :param key: The header key to set. :param values: An iterable of values to set for the key. .. versionadded:: 1.0
def setlistdefault | ( | self, | |
key, | |||
default | |||
) |
Return the list of values for the key if it is in the headers, otherwise set the header to the list of values given by ``default`` and return that. Unlike :meth:`MultiDict.setlistdefault`, modifying the returned list will not affect the headers. :param key: The header key to get. :param default: An iterable of values to set for the key if it is not in the headers. .. versionadded:: 1.0
def to_wsgi_list | ( | self | ) |
Convert the headers into a list suitable for WSGI. The values are byte strings in Python 2 converted to latin1 and unicode strings in Python 3 for the WSGI server to encode. :return: list
def update | ( | self, | |
* | args, | ||
** | kwargs | ||
) |
Replace headers in this object with items from another headers object and keyword arguments. To extend existing keys instead of replacing, use :meth:`extend` instead. If provided, the first argument can be another :class:`Headers` object, a :class:`MultiDict`, :class:`dict`, or iterable of pairs. .. versionadded:: 1.0
def values | ( | self | ) |
|
static |