class documentation

class CombinedMultiDict(ImmutableMultiDictMixin, MultiDict):

View In Hierarchy

A read only MultiDict that you can pass multiple MultiDict instances as sequence and it will combine the return values of all wrapped dicts:

>>> from werkzeug.datastructures import CombinedMultiDict, MultiDict
>>> post = MultiDict([('foo', 'bar')])
>>> get = MultiDict([('blub', 'blah')])
>>> combined = CombinedMultiDict([get, post])
>>> combined['foo']
'bar'
>>> combined['blub']
'blah'

This works for all read operations and will raise a TypeError for methods that usually change data which isn't possible.

From Werkzeug 0.3 onwards, the KeyError raised by this class is also a subclass of the ~exceptions.BadRequest HTTP exception and will render a page for a 400 BAD REQUEST if caught in a catch-all for HTTP exceptions.

Class Method fromkeys Undocumented
Method __contains__ Undocumented
Method __getitem__ Return the first data value for this key; raises KeyError if not found.
Method __init__ Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method __reduce​_ex__ Undocumented
Method __repr__ Undocumented
Method copy Return a shallow mutable copy of this object.
Method get No summary
Method getlist No summary
Method has​_key
Deprecated since version 2.0: Will be removed in Werkzeug 2.1. Use key in data instead.
Method items Return an iterator of (key, value) pairs.
Method keys Undocumented
Method lists Return a iterator of (key, values) pairs, where values is the list of all values associated with the key.
Method listvalues Return an iterator of all values associated with a key. Zipping keys and this is the same as calling lists:
Method to​_dict Return the contents as regular dict. If flat is True the returned dict will only have the first item present, if flat is False all values will be returned as lists.
Method values Returns an iterator of the first value on every key's value list.
Instance Variable dicts Undocumented
Method ​_keys​_impl This function exists so __len__ can be implemented more efficiently, saving one list creation from an iterator.

Inherited from ImmutableMultiDictMixin:

Method add Undocumented
Method popitemlist Undocumented
Method poplist Undocumented
Method setlist Undocumented
Method setlistdefault Undocumented
Method ​_iter​_hashitems Undocumented

Inherited from ImmutableDictMixin (via ImmutableMultiDictMixin):

Method __delitem__ Undocumented
Method __hash__ Undocumented
Method __setitem__ Undocumented
Method clear Undocumented
Method pop Undocumented
Method popitem Undocumented
Method setdefault Undocumented
Method update Undocumented
Instance Variable ​_hash​_cache Undocumented

Inherited from MultiDict:

Method __copy__ Undocumented
Method __deepcopy__ Undocumented
Method __getstate__ Undocumented
Method __setitem__ Like add but removes an existing key first.
Method __setstate__ Undocumented
Method add Adds a new value for the key.
Method deepcopy Return a deep copy of this object.
Method pop Pop the first item for a list on the dict. Afterwards the key is removed from the dict, so additional values are discarded:
Method popitem Pop an item from the dict.
Method popitemlist Pop a (key, list) tuple from the dict.
Method poplist Pop the list for a key from the dict. If the key is not in the dict an empty list is returned.
Method setdefault Returns the value for the key if it is in the dict, otherwise it returns default and sets that value for key.
Method setlist Remove the old values for a key and add new ones. Note that the list you pass the values in will be shallow-copied before it is inserted in the dictionary.
Method setlistdefault No summary
Method update update() extends rather than replaces existing key lists:
@classmethod
def fromkeys(cls, keys, value=None):
def __contains__(self, key):

Undocumented

def __getitem__(self, key):
Return the first data value for this key; raises KeyError if not found.
Parameters
keyThe key to be looked up.
Raises
KeyErrorif the key does not exist.
def __init__(self, dicts=None):
def __iter__(self):
def __len__(self):

Undocumented

def __reduce_ex__(self, protocol):
def __repr__(self):
def copy(self):

Return a shallow mutable copy of this object.

This returns a MultiDict representing the data at the time of copying. The copy will no longer reflect changes to the wrapped dicts.

Changed in version 0.15: Return a mutable MultiDict.
def get(self, key, default=None, type=None):

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 ValueError if that is not possible. In this case the function will return the default as if the value was not found:

>>> d = TypeConversionDict(foo='42', bar='blub')
>>> d.get('foo', type=int)
42
>>> d.get('bar', -1, type=int)
-1
Parameters
keyThe key to be looked up.
defaultThe default value to be returned if the key can't be looked up. If not further specified None is returned.
typeA callable that is used to cast the value in the MultiDict. If a ValueError is raised by this callable the default value is returned.
def getlist(self, key, type=None):
Return the list of items for a given key. If that key is not in the MultiDict, the return value will be an empty list. Just like get, getlist accepts a type parameter. All items will be converted with the callable defined there.
Parameters
keyThe key to be looked up.
typeA callable that is used to cast the value in the MultiDict. If a ValueError is raised by this callable the value will be removed from the list.
Returns
a list of all the values for the key.
def has_key(self, key):
Deprecated since version 2.0: Will be removed in Werkzeug 2.1. Use key in data instead.
def items(self, multi=False):
Return an iterator of (key, value) pairs.
Parameters
multiIf set to True the iterator returned will have a pair for each value of each key. Otherwise it will only contain pairs for the first value of each key.
def keys(self):

Undocumented

def lists(self):
Return a iterator of (key, values) pairs, where values is the list of all values associated with the key.
def listvalues(self):

Return an iterator of all values associated with a key. Zipping keys and this is the same as calling lists:

>>> d = MultiDict({"foo": [1, 2, 3]})
>>> zip(d.keys(), d.listvalues()) == d.lists()
True
def to_dict(self, flat=True):
Return the contents as regular dict. If flat is True the returned dict will only have the first item present, if flat is False all values will be returned as lists.
Parameters
flatIf set to False the dict returned will have lists with all the values in it. Otherwise it will only contain the first item for each key.
Returns
a dict
def values(self):
Returns an iterator of the first value on every key's value list.
dicts =

Undocumented

def _keys_impl(self):
This function exists so __len__ can be implemented more efficiently, saving one list creation from an iterator.