Add Headers.mutablecopy()

This commit is contained in:
Tom Christie 2018-07-13 13:35:35 +01:00
parent 31b25a8757
commit 140cf99df9
2 changed files with 10 additions and 0 deletions

View File

@ -155,6 +155,9 @@ class Headers(typing.Mapping[str, str]):
if item_key == get_header_key
]
def mutablecopy(self):
return MutableHeaders(self._list[:])
def __getitem__(self, key: str):
get_header_key = key.lower().encode("latin-1")
for header_key, header_value in self._list:

View File

@ -51,6 +51,13 @@ def test_mutable_headers():
assert dict(h) == {"b": "4"}
def test_headers_mutablecopy():
h = Headers([(b"a", b"123"), (b"a", b"456"), (b"b", b"789")])
c = h.mutablecopy()
assert c.items() == [("a", "123"), ("a", "456"), ("b", "789")]
c["a"] = "abc"
assert c.items() == [("b", "789"), ("a", "abc")]
def test_queryparams():
q = QueryParams([("a", "123"), ("a", "456"), ("b", "789")])
assert "a" in q