Back to index

moin  1.9.0~rc2
Public Member Functions | Public Attributes | Static Public Attributes | Static Private Attributes
MoinMoin.support.werkzeug.datastructures.CombinedMultiDict Class Reference
Inheritance diagram for MoinMoin.support.werkzeug.datastructures.CombinedMultiDict:
Inheritance graph
[legend]
Collaboration diagram for MoinMoin.support.werkzeug.datastructures.CombinedMultiDict:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def fromkeys
def __getitem__
def get
def getlist
def keys
def iteritems
def itervalues
def values
def items
def iterlists
def lists
def iterlistvalues
def listvalues
def iterkeys
def copy
def to_dict
def __len__
def __contains__
def __repr__
def popitemlist
def poplist
def setlist
def setlistdefault
def setdefault
def update
def pop
def popitem
def __setitem__
def __delitem__
def clear
def __setitem__
def setlist
def setdefault
def setlistdefault
def update
def pop
def popitem
def poplist
def popitemlist

Public Attributes

 dicts

Static Public Attributes

 has_key = __contains__
 KeyError = None
 lists = dict.items

Static Private Attributes

 __iter__ = iterkeys

Detailed Description

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

>>> from werkzeug import MultiDict, CombinedMultiDict
>>> 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 :exc:`~exceptions.BadRequest` HTTP exception and will
render a page for a ``400 BAD REQUEST`` if catched in a catch-all for HTTP
exceptions.

Definition at line 934 of file datastructures.py.


Constructor & Destructor Documentation

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 957 of file datastructures.py.

00957 
00958     def __init__(self, dicts=None):
00959         self.dicts = dicts or []


Member Function Documentation

Definition at line 1057 of file datastructures.py.

01057 
01058     def __contains__(self, key):
01059         for d in self.dicts:
01060             if key in d:
01061                 return True
01062         return False

Definition at line 102 of file datastructures.py.

00102 
00103     def __delitem__(self, key):
00104         is_immutable(self)

Here is the call graph for this function:

Here is the caller graph for this function:

Return the first data value for this key;
raises KeyError if not found.

:param key: The key to be looked up.
:raise KeyError: if the key does not exist.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 965 of file datastructures.py.

00965 
00966     def __getitem__(self, key):
00967         for d in self.dicts:
00968             if key in d:
00969                 return d[key]
00970         raise self.KeyError(key)

Definition at line 1054 of file datastructures.py.

01054 
01055     def __len__(self):
01056         return len(self.keys())

Here is the call graph for this function:

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1065 of file datastructures.py.

01065 
01066     def __repr__(self):
01067         return '%s(%r)' % (self.__class__.__name__, self.dicts)
01068 

def MoinMoin.support.werkzeug.datastructures.ImmutableDictMixin.__setitem__ (   self,
  key,
  value 
) [inherited]

Definition at line 99 of file datastructures.py.

00099 
00100     def __setitem__(self, key, value):
00101         is_immutable(self)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.__setitem__ (   self,
  key,
  value 
) [inherited]
Set an item as list.

Definition at line 285 of file datastructures.py.

00285 
00286     def __setitem__(self, key, value):
00287         """Set an item as list."""
00288         dict.__setitem__(self, key, [value])

Here is the caller graph for this function:

Definition at line 105 of file datastructures.py.

00105 
00106     def clear(self):
00107         is_immutable(self)
00108 

Here is the call graph for this function:

Return a shallow copy of this object.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1035 of file datastructures.py.

01035 
01036     def copy(self):
01037         """Return a shallow copy of this object."""
01038         return self.__class__(self.dicts[:])

Definition at line 961 of file datastructures.py.

00961 
00962     def fromkeys(cls):
00963         raise TypeError('cannot create %r instances by fromkeys' %
00964                         cls.__name__)

def MoinMoin.support.werkzeug.datastructures.CombinedMultiDict.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 :exc:`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

: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:`MultiDict`.  If a :exc:`ValueError` is raised
     by this callable the default value is returned.

Reimplemented from MoinMoin.support.werkzeug.datastructures.TypeConversionDict.

Definition at line 971 of file datastructures.py.

00971 
00972     def get(self, key, default=None, type=None):
00973         for d in self.dicts:
00974             if key in d:
00975                 if type is not None:
00976                     try:
00977                         return type(d[key])
00978                     except ValueError:
00979                         continue
00980                 return d[key]
00981         return default

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.datastructures.CombinedMultiDict.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 as `get`
`getlist` accepts a `type` parameter.  All items will be converted
with the callable defined there.

:param key: The key to be looked up.
:param type: A callable that is used to cast the value in the
     :class:`MultiDict`.  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.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 982 of file datastructures.py.

00982 
00983     def getlist(self, key, type=None):
00984         rv = []
00985         for d in self.dicts:
00986             rv.extend(d.getlist(key, type))
00987         return rv

Return a list of ``(key, value)`` pairs.

:param multi: If set to `True` the list returned will have a
      pair for each value of each key.  Ohterwise it
      will only contain pairs for the first value of
      each key.

:return: a :class:`list`

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1011 of file datastructures.py.

01011 
01012     def items(self, multi=False):
01013         return list(self.iteritems(multi))

Here is the call graph for this function:

Here is the caller graph for this function:

Like :meth:`items` but returns an iterator.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 994 of file datastructures.py.

00994 
00995     def iteritems(self, multi=False):
00996         found = set()
00997         for d in self.dicts:
00998             for key, value in d.iteritems(multi):
00999                 if multi:
01000                     yield key, value
01001                 elif key not in found:
01002                     found.add(key)
01003                     yield key, value

Definition at line 1030 of file datastructures.py.

01030 
01031     def iterkeys(self):
01032         return iter(self.keys())

Here is the call graph for this function:

Here is the caller graph for this function:

Return a list of all values associated with a key.

:return: a class:`list`

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1014 of file datastructures.py.

01014 
01015     def iterlists(self):
01016         rv = {}
01017         for d in self.dicts:
01018             for key, values in d.iterlists():
01019                 rv.setdefault(key, []).extend(values)
01020         return rv.iteritems()

like :meth:`listvalues` but returns an iterator.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1024 of file datastructures.py.

01024 
01025     def iterlistvalues(self):
01026         return (x[0] for x in self.lists())

Like :meth:`values` but returns an iterator.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1004 of file datastructures.py.

01004 
01005     def itervalues(self):
01006         for key, value in self.iteritems():
01007             yield value

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 988 of file datastructures.py.

00988 
00989     def keys(self):
00990         rv = set()
00991         for d in self.dicts:
00992             rv.update(d.keys())
00993         return list(rv)

Here is the caller graph for this function:

Definition at line 1021 of file datastructures.py.

01021 
01022     def lists(self):
01023         return list(self.iterlists())

Here is the call graph for this function:

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

>>> d = MultiDict({"foo": [1, 2, 3]})
>>> zip(d.keys(), d.listvalues()) == d.lists()
True

:return: a :class:`list`

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1027 of file datastructures.py.

01027 
01028     def listvalues(self):
01029         return list(self.iterlistvalues())

Here is the call graph for this function:

def MoinMoin.support.werkzeug.datastructures.ImmutableDictMixin.pop (   self,
  key,
  default = None 
) [inherited]

Definition at line 93 of file datastructures.py.

00093 
00094     def pop(self, key, default=None):
00095         is_immutable(self)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.pop (   self,
  key,
  default = _missing 
) [inherited]
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

:param key: the key to pop.
:param default: if provided the value to return if the key was
        not in the dictionary.

Definition at line 465 of file datastructures.py.

00465 
00466     def pop(self, key, default=_missing):
00467         """Pop the first item for a list on the dict.  Afterwards the
00468         key is removed from the dict, so additional values are discarded:
00469 
00470         >>> d = MultiDict({"foo": [1, 2, 3]})
00471         >>> d.pop("foo")
00472         1
00473         >>> "foo" in d
00474         False
00475 
00476         :param key: the key to pop.
00477         :param default: if provided the value to return if the key was
00478                         not in the dictionary.
00479         """
00480         if default is not _missing:
00481             return dict.pop(self, key, default)
00482         try:
00483             return dict.pop(self, key)[0]
00484         except KeyError, e:
00485             raise self.KeyError(str(e))

Here is the caller graph for this function:

Definition at line 96 of file datastructures.py.

00096 
00097     def popitem(self):
00098         is_immutable(self)

Here is the call graph for this function:

Pop an item from the dict.

Definition at line 486 of file datastructures.py.

00486 
00487     def popitem(self):
00488         """Pop an item from the dict."""
00489         try:
00490             item = dict.popitem(self)
00491             return (item[0], item[1][0])
00492         except KeyError, e:
00493             raise self.KeyError(str(e))

Definition at line 117 of file datastructures.py.

00117 
00118     def popitemlist(self):
00119         is_immutable(self)

Here is the call graph for this function:

Pop a ``(key, list)`` tuple from the dict.

Definition at line 504 of file datastructures.py.

00504 
00505     def popitemlist(self):
00506         """Pop a ``(key, list)`` tuple from the dict."""
00507         try:
00508             return dict.popitem(self)
00509         except KeyError, e:
00510             raise self.KeyError(str(e))

Definition at line 120 of file datastructures.py.

00120 
00121     def poplist(self, key):
00122         is_immutable(self)

Here is the call graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.poplist (   self,
  key 
) [inherited]
Pop the list for a key from the dict.  If the key is not in the dict
an empty list is returned.

.. versionchanged:: 0.5
   If the key does no longer exist a list is returned instead of
   raising an error.

Definition at line 494 of file datastructures.py.

00494 
00495     def poplist(self, key):
00496         """Pop the list for a key from the dict.  If the key is not in the dict
00497         an empty list is returned.
00498 
00499         .. versionchanged:: 0.5
00500            If the key does no longer exist a list is returned instead of
00501            raising an error.
00502         """
00503         return dict.pop(self, key, [])

def MoinMoin.support.werkzeug.datastructures.ImmutableDictMixin.setdefault (   self,
  key,
  default = None 
) [inherited]

Definition at line 87 of file datastructures.py.

00087 
00088     def setdefault(self, key, default=None):
00089         is_immutable(self)

Here is the call graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.setdefault (   self,
  key,
  default = None 
) [inherited]
Returns the value for the key if it is in the dict, otherwise it
returns `default` and sets that value for `key`.

:param key: The key to be looked up.
:param default: The default value to be returned if the key is not
        in the dict.  If not further specified it's `None`.

Definition at line 333 of file datastructures.py.

00333 
00334     def setdefault(self, key, default=None):
00335         """Returns the value for the key if it is in the dict, otherwise it
00336         returns `default` and sets that value for `key`.
00337 
00338         :param key: The key to be looked up.
00339         :param default: The default value to be returned if the key is not
00340                         in the dict.  If not further specified it's `None`.
00341         """
00342         if key not in self:
00343             self[key] = default
00344         else:
00345             default = self[key]
00346         return default

def MoinMoin.support.werkzeug.datastructures.ImmutableMultiDictMixin.setlist (   self,
  key,
  new_list 
) [inherited]

Definition at line 123 of file datastructures.py.

00123 
00124     def setlist(self, key, new_list):
00125         is_immutable(self)

Here is the call graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.setlist (   self,
  key,
  new_list 
) [inherited]
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']

:param key: The key for which the values are set.
:param new_list: An iterable with the new values for the key.  Old values
         are removed first.

Definition at line 315 of file datastructures.py.

00315 
00316     def setlist(self, key, new_list):
00317         """Remove the old values for a key and add new ones.  Note that the list
00318         you pass the values in will be shallow-copied before it is inserted in
00319         the dictionary.
00320 
00321         >>> d = MultiDict()
00322         >>> d.setlist('foo', ['1', '2'])
00323         >>> d['foo']
00324         '1'
00325         >>> d.getlist('foo')
00326         ['1', '2']
00327 
00328         :param key: The key for which the values are set.
00329         :param new_list: An iterable with the new values for the key.  Old values
00330                          are removed first.
00331         """
00332         dict.__setitem__(self, key, list(new_list))

def MoinMoin.support.werkzeug.datastructures.ImmutableMultiDictMixin.setlistdefault (   self,
  key,
  default_list = None 
) [inherited]

Definition at line 126 of file datastructures.py.

00126 
00127     def setlistdefault(self, key, default_list=None):
00128         is_immutable(self)
00129 

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.setlistdefault (   self,
  key,
  default_list = None 
) [inherited]
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]

:param key: The key to be looked up.
:param default: An iterable of default values.  It is either copied
        (in case it was a list) or converted into a list
        before returned.
:return: a :class:`list`

Definition at line 347 of file datastructures.py.

00347 
00348     def setlistdefault(self, key, default_list=None):
00349         """Like `setdefault` but sets multiple values.  The list returned
00350         is not a copy, but the list that is actually used internally.  This
00351         means that you can put new values into the dict by appending items
00352         to the list:
00353 
00354         >>> d = MultiDict({"foo": 1})
00355         >>> d.setlistdefault("foo").extend([2, 3])
00356         >>> d.getlist("foo")
00357         [1, 2, 3]
00358 
00359         :param key: The key to be looked up.
00360         :param default: An iterable of default values.  It is either copied
00361                         (in case it was a list) or converted into a list
00362                         before returned.
00363         :return: a :class:`list`
00364         """
00365         if key not in self:
00366             default_list = list(default_list or ())
00367             dict.__setitem__(self, key, default_list)
00368         else:
00369             default_list = dict.__getitem__(self, key)
00370         return default_list

Here is the caller graph for this function:

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.

:param flat: If 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.
:return: a :class:`dict`

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1039 of file datastructures.py.

01039 
01040     def to_dict(self, flat=True):
01041         """Return the contents as regular dict.  If `flat` is `True` the
01042         returned dict will only have the first item present, if `flat` is
01043         `False` all values will be returned as lists.
01044 
01045         :param flat: If set to `False` the dict returned will have lists
01046                      with all the values in it.  Otherwise it will only
01047                      contain the first item for each key.
01048         :return: a :class:`dict`
01049         """
01050         rv = {}
01051         for d in reversed(self.dicts):
01052             rv.update(d.to_dict(flat))
01053         return rv

def MoinMoin.support.werkzeug.datastructures.ImmutableDictMixin.update (   self,
  args,
  kwargs 
) [inherited]

Definition at line 90 of file datastructures.py.

00090 
00091     def update(self, *args, **kwargs):
00092         is_immutable(self)

Here is the call graph for this function:

Here is the caller graph for this function:

def MoinMoin.support.werkzeug.datastructures.MultiDict.update (   self,
  other_dict 
) [inherited]
update() extends rather than replaces existing key lists.

Definition at line 453 of file datastructures.py.

00453 
00454     def update(self, other_dict):
00455         """update() extends rather than replaces existing key lists."""
00456         if isinstance(other_dict, MultiDict):
00457             for key, value_list in other_dict.iterlists():
00458                 self.setlistdefault(key, []).extend(value_list)
00459         elif isinstance(other_dict, dict):
00460             for key, value in other_dict.items():
00461                 self.setlistdefault(key, []).append(value)
00462         else:
00463             for key, value in other_dict:
00464                 self.setlistdefault(key, []).append(value)

Here is the call graph for this function:

Here is the caller graph for this function:

Returns a list of the first value on every key's value list.

:return: a :class:`list`.

Reimplemented from MoinMoin.support.werkzeug.datastructures.MultiDict.

Definition at line 1008 of file datastructures.py.

01008 
01009     def values(self):
01010         return list(self.itervalues())

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 1033 of file datastructures.py.

Definition at line 958 of file datastructures.py.

Definition at line 1063 of file datastructures.py.

Definition at line 254 of file datastructures.py.

Definition at line 387 of file datastructures.py.


The documentation for this class was generated from the following file: