mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #2149 from mhils/multidictview-copy
Add MultiDictView.copy()
This commit is contained in:
commit
2d016775fe
@ -4,7 +4,7 @@ from collections.abc import MutableMapping
|
||||
from mitmproxy.types import serializable
|
||||
|
||||
|
||||
class _MultiDict(MutableMapping, serializable.Serializable, metaclass=ABCMeta):
|
||||
class _MultiDict(MutableMapping, metaclass=ABCMeta):
|
||||
def __repr__(self):
|
||||
fields = (
|
||||
repr(field)
|
||||
@ -171,18 +171,8 @@ class _MultiDict(MutableMapping, serializable.Serializable, metaclass=ABCMeta):
|
||||
coll.append([key, values])
|
||||
return coll
|
||||
|
||||
def get_state(self):
|
||||
return self.fields
|
||||
|
||||
def set_state(self, state):
|
||||
self.fields = tuple(tuple(x) for x in state)
|
||||
|
||||
@classmethod
|
||||
def from_state(cls, state):
|
||||
return cls(state)
|
||||
|
||||
|
||||
class MultiDict(_MultiDict):
|
||||
class MultiDict(_MultiDict, serializable.Serializable):
|
||||
def __init__(self, fields=()):
|
||||
super().__init__()
|
||||
self.fields = tuple(
|
||||
@ -197,6 +187,16 @@ class MultiDict(_MultiDict):
|
||||
def _kconv(key):
|
||||
return key
|
||||
|
||||
def get_state(self):
|
||||
return self.fields
|
||||
|
||||
def set_state(self, state):
|
||||
self.fields = tuple(tuple(x) for x in state)
|
||||
|
||||
@classmethod
|
||||
def from_state(cls, state):
|
||||
return cls(state)
|
||||
|
||||
|
||||
class MultiDictView(_MultiDict):
|
||||
"""
|
||||
@ -227,3 +227,6 @@ class MultiDictView(_MultiDict):
|
||||
@fields.setter
|
||||
def fields(self, value):
|
||||
self._setter(value)
|
||||
|
||||
def copy(self):
|
||||
return MultiDict(self.fields)
|
||||
|
@ -200,3 +200,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()
|
||||
|
Loading…
Reference in New Issue
Block a user