class documentation

class OrderedMultiDict(MultiDict):

Known subclasses: werkzeug.datastructures.ImmutableOrderedMultiDict

View In Hierarchy

Works like a regular MultiDict but preserves the order of the fields. To convert the ordered multi dict into a list you can use the items method and pass it multi=True.

In general an OrderedMultiDict is an order of magnitude slower than a MultiDict.

note

Due to a limitation in Python you cannot convert an ordered multi dict into a regular dict by using dict(multidict). Instead you have to use the to_dict method, otherwise the internal bucket objects are exposed.

Method __delitem__ Undocumented
Method __eq__ Undocumented
Method __getitem__ Return the first data value for this key; raises KeyError if not found.
Method __getstate__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __reduce​_ex__ Undocumented
Method __setitem__ Like add but removes an existing key first.
Method __setstate__ Undocumented
Method add Adds a new value for the key.
Method getlist No summary
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 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 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:
Method values Returns an iterator of the first value on every key's value list.
Class Variable __hash__ Undocumented
Instance Variable ​_first​_bucket Undocumented
Instance Variable ​_last​_bucket Undocumented

Inherited from MultiDict:

Method __copy__ Undocumented
Method __deepcopy__ Undocumented
Method __repr__ Undocumented
Method copy Return a shallow copy of this object.
Method deepcopy Return a deep copy of this object.
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 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.

Inherited from TypeConversionDict (via MultiDict):

Method get No summary
def __delitem__(self, key):

Undocumented

def __eq__(self, other):

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 __getstate__(self):
def __init__(self, mapping=None):
def __iter__(self):
def __reduce_ex__(self, protocol):

Undocumented

def __setitem__(self, key, value):
Like add but removes an existing key first.
Parameters
keythe key for the value.
valuethe value to set.
def __setstate__(self, values):
def add(self, key, value):

Adds a new value for the key.

New in version 0.6.
Parameters
keythe key for the value.
valuethe value to add.
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 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 pop(self, key, default=_missing):

Pop the first item for a list on the dict. Afterwards the key is removed from the dict, so additional values are discarded:

>>> d = MultiDict({"foo": [1, 2, 3]})
>>> d.pop("foo")
1
>>> "foo" in d
False
Parameters
keythe key to pop.
defaultif provided the value to return if the key was not in the dictionary.
def popitem(self):
Pop an item from the dict.
def popitemlist(self):
Pop a (key, list) tuple from the dict.
def poplist(self, key):

Pop the list for a key from the dict. If the key is not in the dict an empty list is returned.

Changed in version 0.5: If the key does no longer exist a list is returned instead of raising an error.
def setlist(self, key, new_list):

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.

>>> d = MultiDict()
>>> d.setlist('foo', ['1', '2'])
>>> d['foo']
'1'
>>> d.getlist('foo')
['1', '2']
Parameters
keyThe key for which the values are set.
new​_listAn iterable with the new values for the key. Old values are removed first.
def setlistdefault(self, key, default_list=None):

Like setdefault but sets multiple values. The list returned is not a copy, but the list that is actually used internally. This means that you can put new values into the dict by appending items to the list:

>>> d = MultiDict({"foo": 1})
>>> d.setlistdefault("foo").extend([2, 3])
>>> d.getlist("foo")
[1, 2, 3]
Parameters
keyThe key to be looked up.
default​_listAn iterable of default values. It is either copied (in case it was a list) or converted into a list before returned.
Returns
a list
def update(self, mapping):

update() extends rather than replaces existing key lists:

>>> a = MultiDict({'x': 1})
>>> b = MultiDict({'x': 2, 'y': 3})
>>> a.update(b)
>>> a
MultiDict([('y', 3), ('x', 1), ('x', 2)])

If the value list for a key in other_dict is empty, no new values will be added to the dict and the key will not be created:

>>> x = {'empty_list': []}
>>> y = MultiDict()
>>> y.update(x)
>>> y
MultiDict([])
def values(self):
Returns an iterator of the first value on every key's value list.
__hash__ =

Undocumented

_first_bucket =

Undocumented

_last_bucket =

Undocumented