mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
multidict: remove to_dict
We never use it, and it is dangerously ambiguous when a key is associated with a list.
This commit is contained in:
parent
18ee6255c0
commit
cc8b422d9d
@ -174,27 +174,6 @@ class _MultiDict(MutableMapping, serializable.Serializable, metaclass=ABCMeta):
|
|||||||
coll.append([key, values])
|
coll.append([key, values])
|
||||||
return coll
|
return coll
|
||||||
|
|
||||||
def to_dict(self):
|
|
||||||
"""
|
|
||||||
Get the MultiDict as a plain Python dict.
|
|
||||||
Keys with multiple values are returned as lists.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
.. code-block:: python
|
|
||||||
|
|
||||||
# Simple dict with duplicate values.
|
|
||||||
>>> d = MultiDict([("name", "value"), ("a", False), ("a", 42)])
|
|
||||||
>>> d.to_dict()
|
|
||||||
{
|
|
||||||
"name": "value",
|
|
||||||
"a": [False, 42]
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
return {
|
|
||||||
k: v for k, v in self.collect()
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
return self.fields
|
return self.fields
|
||||||
|
|
||||||
|
@ -172,13 +172,6 @@ class TestMultiDict:
|
|||||||
assert list(md.items()) == [("foo", "bar"), ("bar", "baz")]
|
assert list(md.items()) == [("foo", "bar"), ("bar", "baz")]
|
||||||
assert list(md.items(multi=True)) == [("foo", "bar"), ("bar", "baz"), ("Bar", "bam")]
|
assert list(md.items(multi=True)) == [("foo", "bar"), ("bar", "baz"), ("Bar", "bam")]
|
||||||
|
|
||||||
def test_to_dict(self):
|
|
||||||
md = self._multi()
|
|
||||||
assert md.to_dict() == {
|
|
||||||
"foo": "bar",
|
|
||||||
"bar": ["baz", "bam"]
|
|
||||||
}
|
|
||||||
|
|
||||||
def test_state(self):
|
def test_state(self):
|
||||||
md = self._multi()
|
md = self._multi()
|
||||||
assert len(md.get_state()) == 3
|
assert len(md.get_state()) == 3
|
||||||
|
Loading…
Reference in New Issue
Block a user