Skip to content
Myr

cookiejar_from_dict

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

#12

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 7e25517 · Browse files · 1 file+25 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

1 file+25 added−1 removed

  • other:+25 added−1 removed

1 file+25 added−1 removed

modified:requests/utils.py+25 added-1 removed
7 unmodified lines
8that are also useful for external consumption.910"""1112import Cookie13import cookielib141516def dict_from_cookiejar(cookiejar):14 """Returns a key/value dictoinary from a CookieJar."""17 """Returns a key/value dictionary from a CookieJar."""1819 cookie_dict = {}2021 for _, cookies in cookiejar._cookies.items():
2 unmodified lines
24 cookie_dict[cookie.name] = cookie.value2526 return cookie_dict272829def cookiejar_from_dict(cookie_dict, domain=None):30 """Returns a CookieJar from a key/value dictoinary."""3132 # create cookiejar33 cj = cookielib.CookieJar()3435 for k, v in cookie_dict.items():3637 # create cookie38 ck = Cookie.SimpleCookie()39 ck.name = v40 ck.expires = 041 ck.path = '/'42 ck.domain = domain4344 # add cookie to cookiejar45 cj.set_cookie(ck)4647 return cj48