Allow RequestsCookieJar to be updated with cookies from a CookieJar
authorChase Sterling <chase.sterling@gmail.com>
Thu, 14 Feb 2013 06:05:42 +0000 (01:05 -0500)
committerChase Sterling <chase.sterling@gmail.com>
Thu, 14 Feb 2013 06:05:42 +0000 (01:05 -0500)
requests/cookies.py

index eb6c3146106a9b196db76d608eae61383394908a..365728a3d5df6f01fe007c89beb7dac9f9cc47db 100644 (file)
@@ -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,