From cc8b422d9d4cdf5e6933567ec7be45f59ca95f3a Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 21 Oct 2016 11:41:54 +1300 Subject: [PATCH] multidict: remove to_dict We never use it, and it is dangerously ambiguous when a key is associated with a list. --- mitmproxy/types/multidict.py | 21 --------------------- test/mitmproxy/test_types_multidict.py | 7 ------- 2 files changed, 28 deletions(-) diff --git a/mitmproxy/types/multidict.py b/mitmproxy/types/multidict.py index e02d28a9c..31a1f22b7 100644 --- a/mitmproxy/types/multidict.py +++ b/mitmproxy/types/multidict.py @@ -174,27 +174,6 @@ class _MultiDict(MutableMapping, serializable.Serializable, metaclass=ABCMeta): coll.append([key, values]) 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): return self.fields diff --git a/test/mitmproxy/test_types_multidict.py b/test/mitmproxy/test_types_multidict.py index cf80c05e9..e0bbc9b14 100644 --- a/test/mitmproxy/test_types_multidict.py +++ b/test/mitmproxy/test_types_multidict.py @@ -172,13 +172,6 @@ class TestMultiDict: assert list(md.items()) == [("foo", "bar"), ("bar", "baz")] 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): md = self._multi() assert len(md.get_state()) == 3