MCPcopy
hub / github.com/pallets/werkzeug / CombinedMultiDict

Class CombinedMultiDict

src/werkzeug/datastructures/structures.py:816–958  ·  view source on GitHub ↗

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.datastructures import CombinedMultiDict, MultiDict >>> post = MultiDict([('foo', 'bar')]) >>> get = Mu

Source from the content-addressed store, hash-verified

814
815
816class CombinedMultiDict(ImmutableMultiDictMixin[K, V], MultiDict[K, V]): # type: ignore[misc]
817 """A read only :class:`MultiDict` that you can pass multiple :class:`MultiDict`
818 instances as sequence and it will combine the return values of all wrapped
819 dicts:
820
821 >>> from werkzeug.datastructures import CombinedMultiDict, MultiDict
822 >>> post = MultiDict([('foo', 'bar')])
823 >>> get = MultiDict([('blub', 'blah')])
824 >>> combined = CombinedMultiDict([get, post])
825 >>> combined['foo']
826 'bar'
827 >>> combined['blub']
828 'blah'
829
830 This works for all read operations and will raise a `TypeError` for
831 methods that usually change data which isn't possible.
832
833 From Werkzeug 0.3 onwards, the `KeyError` raised by this class is also a
834 subclass of the :exc:`~exceptions.BadRequest` HTTP exception and will
835 render a page for a ``400 BAD REQUEST`` if caught in a catch-all for HTTP
836 exceptions.
837 """
838
839 def __reduce_ex__(self, protocol: t.SupportsIndex) -> t.Any:
840 return type(self), (self.dicts,)
841
842 def __init__(self, dicts: cabc.Iterable[MultiDict[K, V]] | None = None) -> None:
843 super().__init__()
844 self.dicts: list[MultiDict[K, V]] = list(dicts or ())
845
846 @classmethod
847 def fromkeys(cls, keys: t.Any, value: t.Any = None) -> t.NoReturn:
848 raise TypeError(f"cannot create {cls.__name__!r} instances by fromkeys")
849
850 def __getitem__(self, key: K) -> V:
851 for d in self.dicts:
852 if key in d:
853 return d[key]
854 raise exceptions.BadRequestKeyError(key)
855
856 @t.overload # type: ignore[override]
857 def get(self, key: K) -> V | None: ...
858 @t.overload
859 def get(self, key: K, default: V) -> V: ...
860 @t.overload
861 def get(self, key: K, default: T) -> V | T: ...
862 @t.overload
863 def get(self, key: str, type: cabc.Callable[[V], T]) -> T | None: ...
864 @t.overload
865 def get(self, key: str, default: T, type: cabc.Callable[[V], T]) -> T: ...
866 def get( # type: ignore[misc]
867 self,
868 key: K,
869 default: V | T | None = None,
870 type: cabc.Callable[[V], T] | None = None,
871 ) -> V | T | None:
872 for d in self.dicts:
873 if key in d:

Callers 2

get_environMethod · 0.85
valuesMethod · 0.85

Calls

no outgoing calls

Tested by 1

get_environMethod · 0.68