Skip to content
Myr

Merge pull request #1194 from gazpachoking/cookiejar_update

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

Allow RequestsCookieJar to be updated with cookies from a CookieJar

authored by Kenneth Reitz · committed by Kenneth Reitz · parents f73bda0, f3393fb · Browse files · 1 file+8 added−4 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+8 added−4 removed

  • other:+8 added−4 removed

1 file+8 added−4 removed

modified:requests/cookies.py+8 added-4 removed
238 unmodified lines
239 def __getitem__(self, name):240 """Dict-like __getitem__() for compatibility with client code. Throws exception241 if there are more than one cookie with name. In that case, use the more242 explicit get() method instead. Caution: operation is O(n), not O(1)."""243 if isinstance(name, cookielib.Cookie):244 name = name.name243244 return self._find_no_duplicates(name)245246 def __setitem__(self, name, value):247 """Dict-like __setitem__ for compatibility with client code. Throws exception248 if there is already a cookie of that name in the jar. In that case, use the more249 explicit set() method instead."""252 if isinstance(name, cookielib.Cookie):253 name = name.name250251 self.set(name, value)252253 def __delitem__(self, name):254 """Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name()."""255 remove_cookie_by_name(self, name)256257 def update(self, other):258 """Updates this jar with cookies from another CookieJar or dict-like"""259 if isinstance(other, cookielib.CookieJar):260 for cookie in other:261 self.set_cookie(cookie)262 else:263 super(RequestsCookieJar, self).update(other)264265 def _find(self, name, domain=None, path=None):266 """Requests uses this method internally to get cookie values. Takes as args name267 and optional domain and path. Returns a cookie.value. If there are conflicting cookies,268 _find arbitrarily chooses one. See _find_no_duplicates if you want an exception thrown
115 unmodified lines