From de1de3f626c142df759cd14aac5c46fd878d2d3c Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Tue, 14 Mar 2017 02:18:02 +0100 Subject: [PATCH] add MultiDictView.copy --- mitmproxy/types/multidict.py | 3 +++ test/mitmproxy/types/test_multidict.py | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/mitmproxy/types/multidict.py b/mitmproxy/types/multidict.py index 31a1f22b7..ac49200b6 100644 --- a/mitmproxy/types/multidict.py +++ b/mitmproxy/types/multidict.py @@ -230,3 +230,6 @@ class MultiDictView(_MultiDict): @fields.setter def fields(self, value): self._setter(value) + + def copy(self): + return MultiDict(self.fields) diff --git a/test/mitmproxy/types/test_multidict.py b/test/mitmproxy/types/test_multidict.py index 9b13c5cd8..7d38f6ba6 100644 --- a/test/mitmproxy/types/test_multidict.py +++ b/test/mitmproxy/types/test_multidict.py @@ -205,3 +205,12 @@ class TestMultiDictView: tv["c"] = "b" assert p.vals == (("a", "b"), ("c", "b")) assert tv["a"] == "b" + + def test_copy(self): + p = TParent() + tv = multidict.MultiDictView(p.getter, p.setter) + c = tv.copy() + assert isinstance(c, multidict.MultiDict) + assert tv.items() == c.items() + c["foo"] = "bar" + assert tv.items() != c.items()