Skip to content
Myr

Made cookies construct-able from a list of tuples (#1211)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Added test which checks that cookie might be built from a list of tuples (#1209) * Made cookies constructable from a list of tuples (#1209)

authored by cdeler · committed by GitHub · parent 15c1e42 · Browse files · 3 files+15 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+15 added−1 removed

  • tests:+10 added−0 removed
  • other:+5 added−1 removed

3 files+15 added−1 removed

modified:httpx/_models.py+4 added
1045 unmodified lines
1046 self.jar = CookieJar()1047 if isinstance(cookies, dict):1048 for key, value in cookies.items():1049 self.set(key, value)1050 elif isinstance(cookies, list):1051 self.jar = CookieJar()1052 for key, value in cookies:1053 self.set(key, value)1054 elif isinstance(cookies, Cookies):1055 self.jar = CookieJar()1056 for cookie in cookies.jar:1057 self.jar.set_cookie(cookie)
160 unmodified lines
modified:httpx/_types.py+1 added-1 removed
43 unmodified lines
44 Sequence[Tuple[str, str]],45 Sequence[Tuple[bytes, bytes]],46]4748CookieTypes = Union["Cookies", CookieJar, Dict[str, str]]48CookieTypes = Union["Cookies", CookieJar, Dict[str, str], List[Tuple[str, str]]]4950CertTypes = Union[str, Tuple[str, str], Tuple[str, str, str]]51VerifyTypes = Union[str, bool, ssl.SSLContext]52TimeoutTypes = Union[
25 unmodified lines
modified:tests/models/test_cookies.py+10 added
73 unmodified lines
74 cookies = httpx.Cookies(jar)75 cookies.extract_cookies(response)7677 assert len(cookies) == 2787980def test_cookies_can_be_a_list_of_tuples():81 cookies_val = [("name1", "val1"), ("name2", "val2")]8283 cookies = httpx.Cookies(cookies_val)8485 assert len(cookies.items()) == 286 for k, v in cookies_val:87 assert cookies[k] == v