aboutsummaryrefslogtreecommitdiff
path: root/requests/cookies.py
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:26 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:26 -0700
commitc6ee35e00c5709435b3a6b664c44fceb70a918c6 (patch)
tree816307f3c7e1c80f1dd49d617e480e95198d9c18 /requests/cookies.py
parent9f376f89bdf80a40914218d64cd9cd61b25f449d (diff)
downloadpython-requests-c6ee35e00c5709435b3a6b664c44fceb70a918c6.tar
python-requests-c6ee35e00c5709435b3a6b664c44fceb70a918c6.tar.gz
Imported Upstream version 1.2.0
Diffstat (limited to 'requests/cookies.py')
-rw-r--r--requests/cookies.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/requests/cookies.py b/requests/cookies.py
index bd7289e..1235711 100644
--- a/requests/cookies.py
+++ b/requests/cookies.py
@@ -240,18 +240,28 @@ 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)."""
+
return self._find_no_duplicates(name)
def __setitem__(self, name, value):
"""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."""
+
self.set(name, value)
def __delitem__(self, name):
"""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,
@@ -297,8 +307,10 @@ class RequestsCookieJar(cookielib.CookieJar, collections.MutableMapping):
self._cookies_lock = threading.RLock()
def copy(self):
- """This is not implemented. Calling this will throw an exception."""
- raise NotImplementedError
+ """Return a copy of this RequestsCookieJar."""
+ new_cj = RequestsCookieJar()
+ new_cj.update(self)
+ return new_cj
def create_cookie(name, value, **kwargs):