mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
+25
-1
@@ -9,9 +9,12 @@ that are also useful for external consumption.
|
||||
|
||||
"""
|
||||
|
||||
import Cookie
|
||||
import cookielib
|
||||
|
||||
|
||||
def dict_from_cookiejar(cookiejar):
|
||||
"""Returns a key/value dictoinary from a CookieJar."""
|
||||
"""Returns a key/value dictionary from a CookieJar."""
|
||||
|
||||
cookie_dict = {}
|
||||
|
||||
@@ -22,3 +25,24 @@ def dict_from_cookiejar(cookiejar):
|
||||
|
||||
return cookie_dict
|
||||
|
||||
|
||||
def cookiejar_from_dict(cookie_dict, domain=None):
|
||||
"""Returns a CookieJar from a key/value dictoinary."""
|
||||
|
||||
# create cookiejar
|
||||
cj = cookielib.CookieJar()
|
||||
|
||||
for k, v in cookie_dict.items():
|
||||
|
||||
# create cookie
|
||||
ck = Cookie.SimpleCookie()
|
||||
ck.name = v
|
||||
ck.expires = 0
|
||||
ck.path = '/'
|
||||
ck.domain = domain
|
||||
|
||||
# add cookie to cookiejar
|
||||
cj.set_cookie(ck)
|
||||
|
||||
return cj
|
||||
|
||||
|
||||
Reference in New Issue
Block a user