From 87d9d9643c73d6fc7f701263e5c4e93217db022f Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Thu, 14 Feb 2013 01:05:42 -0500 Subject: [PATCH 1/2] Allow RequestsCookieJar to be updated with cookies from a CookieJar --- requests/cookies.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/requests/cookies.py b/requests/cookies.py index eb6c3146..365728a3 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -258,6 +258,14 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): """Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name().""" remove_cookie_by_name(self, name) + def update(self, other): + """Updates this jar with cookies from another CookieJar or dict-like""" + if isinstance(other, cookielib.CookieJar): + for cookie in other: + self.set_cookie(cookie) + else: + super(RequestsCookieJar, self).update(other) + def _find(self, name, domain=None, path=None): """Requests uses this method internally to get cookie values. Takes as args name and optional domain and path. Returns a cookie.value. If there are conflicting cookies, From f3393fb24cc74e9e9aff643e16e0480fcced6ba3 Mon Sep 17 00:00:00 2001 From: Chase Sterling Date: Thu, 14 Feb 2013 22:52:31 -0500 Subject: [PATCH 2/2] Remove ability to from RequestCookieJar __getitem__, __setitem__ to use cookies as keys --- requests/cookies.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/requests/cookies.py b/requests/cookies.py index 365728a3..856258c7 100644 --- a/requests/cookies.py +++ b/requests/cookies.py @@ -240,8 +240,6 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): """Dict-like __getitem__() for compatibility with client code. Throws exception if there are more than one cookie with name. In that case, use the more explicit get() method instead. Caution: operation is O(n), not O(1).""" - if isinstance(name, cookielib.Cookie): - name = name.name return self._find_no_duplicates(name) @@ -249,8 +247,6 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping): """Dict-like __setitem__ for compatibility with client code. Throws exception if there is already a cookie of that name in the jar. In that case, use the more explicit set() method instead.""" - if isinstance(name, cookielib.Cookie): - name = name.name self.set(name, value)