@@ -13,20 +13,21 @@ Multidicts
13
13
several *values * for the same *key *.
14
14
15
15
:mod: `aiohttp.multidict ` has four multidict classes:
16
- :class: `MultiDict `, :class: `MutableMultiDict `, :class: `CIMultiDict `
17
- and :class: `CIMutableMultiDict `.
16
+ :class: `MultiDict `, :class: `MultiDictProxy `, :class: `CIMultiDict `
17
+ and :class: `CIMultiDictProxy `.
18
18
19
+ Immutable proxies (:class: `MultiDictProxy ` and
20
+ :class: `CIMultiDictProxy `) provide a dynamic view on the
21
+ proxied multidict, the view reflects the multidict changes. They are
22
+ implement :class: `~collections.abc.Mapping ` interface.
19
23
20
- Immutable (:class: `MultiDict ` and :class: `CIMultiDict `) classes
21
- doesn't allow to change *muldidict * content. They are implement
22
- :class: `~collections.abc.Mapping ` interface.
23
-
24
- Mutable (:class: `MutableMultiDict ` and :class: `CIMutableMultiDict `)
25
- ones implement :class: `~collections.abc.MutableMapping `.
24
+ Regular mutable (:class: `MultiDict ` and :class: `CIMultiDict `) clases
25
+ implement :class: `~collections.abc.MutableMapping ` and allow to change
26
+ own content.
26
27
27
28
28
29
*Case insensitive * (:class: `CIMultiDict ` and
29
- :class: `CIMutableMultiDict `) ones assumes the *keys * are case
30
+ :class: `CIMultiDictProxy `) ones assumes the *keys * are case
30
31
insensitive, e.g.::
31
32
32
33
>>> dct = CIMultiDict(a='val')
@@ -38,20 +39,20 @@ insensitive, e.g.::
38
39
*Keys * should be a :class: `str `.
39
40
40
41
41
- MultiDict
42
- ---------
42
+ MutableMultiDict
43
+ ----------------
43
44
44
- .. class :: MultiDict (**kwargs)
45
- MultiDict (mapping, **kwargs)
46
- MultiDict (iterable, **kwargs)
45
+ .. class :: MutableMultiDict (**kwargs)
46
+ MutableMultiDict (mapping, **kwargs)
47
+ MutableMultiDict (iterable, **kwargs)
47
48
48
- Create an immutable multidict instance.
49
+ Create a mutable multidict instance.
49
50
50
51
Accepted parameters are the same as for :class: `dict `.
51
52
52
53
If the same key produced several times it will be added, e.g.::
53
54
54
- >>> d = MultiDict( [('a', 1), ('b', 2), ('a', 3)])
55
+ >>> d = MultiDict[('a', 1), ('b', 2), ('a', 3)])
55
56
>>> d
56
57
<MultiDict {'a': 1, 'b': 2, 'a': 3}>
57
58
@@ -65,6 +66,18 @@ MultiDict
65
66
66
67
Raises a :exc: `KeyError ` if key is not in the multidict.
67
68
69
+ .. method :: d[key] = value
70
+
71
+ Set ``d[key] `` to *value *.
72
+
73
+ Replace all items where key is equal to *key * with single item
74
+ ``(key, value) ``.
75
+
76
+ .. method :: del d[key]
77
+
78
+ Remove all items where key is equal to *key * from *d *.
79
+ Raises a :exc: `KeyError ` if *key * is not in the map.
80
+
68
81
.. method :: key in d
69
82
70
83
Return ``True `` if d has a key *key *, else ``False ``.
@@ -78,10 +91,30 @@ MultiDict
78
91
Return an iterator over the keys of the dictionary.
79
92
This is a shortcut for ``iter(d.keys()) ``.
80
93
94
+ .. method :: add(key, value)
95
+
96
+ Append ``(key, value) `` pair to the dictiaonary.
97
+
98
+ .. method :: clear()
99
+
100
+ Remove all items from the dictionary.
101
+
81
102
.. method :: copy()
82
103
83
104
Return a shallow copy of the dictionary.
84
105
106
+ .. method :: extend([other])
107
+
108
+ Extend the dictionary with the key/value pairs from *other *,
109
+ overwriting existing keys.
110
+ Return ``None ``.
111
+
112
+ :meth: `extend ` accepts either another dictionary object or an
113
+ iterable of key/value pairs (as tuples or other iterables of
114
+ length two). If keyword arguments are specified, the dictionary
115
+ is then extended with those key/value pairs:
116
+ ``d.extend(red=1, blue=2) ``.
117
+
85
118
.. method :: getone(key[, default])
86
119
87
120
Return the **first ** value for *key * if *key * is in the
@@ -129,6 +162,12 @@ MultiDict
129
162
View contains all values if *getall * is ``True `` (default) or
130
163
only first key occurrences otherwise.
131
164
165
+ .. method :: setdefault(key[, default])
166
+
167
+ If *key * is in the dictionary, return its the **first ** value.
168
+ If not, insert *key * with a value of *default * and return *default *.
169
+ *default * defaults to ``None ``.
170
+
132
171
133
172
CIMultiDict
134
173
-----------
@@ -138,7 +177,7 @@ CIMultiDict
138
177
CIMultiDict(mapping, **kwargs)
139
178
CIMultiDict(iterable, **kwargs)
140
179
141
- Create an immutable case insensitive multidict instance.
180
+ Create a case insensitive multidict instance.
142
181
143
182
The behavior is the same as of :class: `MultiDict ` but key
144
183
comparsions are case insensitive, e.g.::
@@ -150,53 +189,107 @@ CIMultiDict
150
189
'val'
151
190
>>> dct['a']
152
191
'val'
192
+ >>> dct['b'] = 'new val'
193
+ >>> dct['B']
194
+ 'new val'
153
195
196
+ The class is inherited from :class: `MultiDict `.
154
197
155
- MutableMultiDict
156
- ----------------
157
198
158
- .. class :: MutableMultiDict(**kwargs)
159
- MutableMultiDict(mapping, **kwargs)
160
- MutableMultiDict(iterable, **kwargs)
199
+ MultiDictProxy
200
+ ---------------
161
201
162
- Create a mutable multidict instance.
202
+ .. class :: MultiDictProxy( multidict)
163
203
164
- The class inherited from :class: ` MultiDict ` .
204
+ Create an immutable multidict proxy .
165
205
166
- .. method :: d[key] = value
206
+ It provides a dynamic view on
207
+ the multidict’s entries, which means that when the multidict changes,
208
+ the view reflects these changes.
167
209
168
- Set `` d[key] `` to * value * .
210
+ Raises :exc: ` TypeError ` is * multidict * is not :class: ` MultiDict ` instance .
169
211
170
- Replace all items where key is equal to *key * with single item
171
- ``(key, value) ``.
212
+ .. method :: len(d)
172
213
173
- .. method :: del d[key]
214
+ Return number of items in multidict * d *.
174
215
175
- Remove all items where key is equal to *key * from *d *.
176
- Raises a :exc: `KeyError ` if *key * is not in the map.
216
+ .. method :: d[key]
177
217
178
- .. method :: add( key, value)
218
+ Return the ** first ** item of * d * with key * key *.
179
219
180
- Append `` ( key, value) `` pair to the dictiaonary .
220
+ Raises a :exc: ` KeyError ` if key is not in the multidict .
181
221
182
- .. method :: clear()
222
+ .. method :: key in d
183
223
184
- Remove all items from the dictionary .
224
+ Return `` True `` if d has a key * key *, else `` False `` .
185
225
186
- .. method :: extend([other])
226
+ .. method :: key not in d
187
227
188
- Extend the dictionary with the key/value pairs from *other *,
189
- overwriting existing keys.
190
- Return ``None ``.
228
+ Equivalent to ``not (key in d) ``
191
229
192
- :meth: `extend ` accepts either another dictionary object or an
193
- iterable of key/value pairs (as tuples or other iterables of
194
- length two). If keyword arguments are specified, the dictionary
195
- is then extended with those key/value pairs:
196
- ``d.extend(red=1, blue=2) ``.
230
+ .. method :: iter(d)
197
231
198
- .. method :: setdefault(key[, default])
232
+ Return an iterator over the keys of the dictionary.
233
+ This is a shortcut for ``iter(d.keys()) ``.
199
234
200
- If *key * is in the dictionary, return its the **first ** value.
201
- If not, insert *key * with a value of *default * and return *default *.
202
- *default * defaults to ``None ``.
235
+ .. method :: copy()
236
+
237
+ Return a shallow copy of the dictionary.
238
+
239
+ .. method :: getone(key[, default])
240
+
241
+ Return the **first ** value for *key * if *key * is in the
242
+ dictionary, else *default *.
243
+
244
+ Raises :exc: `KeyError ` if *default * is not given and *key * is not found.
245
+
246
+ ``d[key] `` is equivalent to ``d.getone(key) ``.
247
+
248
+ .. method :: getall(key[, default])
249
+
250
+ Return a list of all values for *key * if *key * is in the
251
+ dictionary, else *default *.
252
+
253
+ Raises :exc: `KeyError ` if *default * is not given and *key * is not found.
254
+
255
+ .. method :: get(key[, default])
256
+
257
+ Return the **first ** value for *key * if *key * is in the
258
+ dictionary, else *default *.
259
+
260
+ If *default * is not given, it defaults to ``None ``, so that this
261
+ method never raises a :exc: `KeyError `.
262
+
263
+ ``d.get(key) `` is equivalent to ``d.getone(key, None) ``.
264
+
265
+ .. method :: keys(getall=True)
266
+
267
+ Return a new view of the dictionary's keys.
268
+
269
+ View contains all keys if *getall * is ``True `` (default) or
270
+ distinct set of ones otherwise.
271
+
272
+ .. method :: keys(getall=True)
273
+
274
+ Return a new view of the dictionary's items (``(key, value) `` pairs).
275
+
276
+ View contains all items if *getall * is ``True `` (default) or
277
+ only first key occurrences otherwise.
278
+
279
+ .. method :: values(getall=True)
280
+
281
+ Return a new view of the dictionary's values.
282
+
283
+ View contains all values if *getall * is ``True `` (default) or
284
+ only first key occurrences otherwise.
285
+
286
+ CIMultiDictProxy
287
+ ----------------
288
+
289
+ .. class :: CIMultiDictProxy(multidict)
290
+
291
+ Case insensitive version of :class: `MultiDictProxy `.
292
+
293
+ Raises :exc: `TypeError ` is *multidict * is not :class: `CIMultiDict ` instance.
294
+
295
+ The class is inherited from :class: `MultiDict `.
0 commit comments