Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Unified Diff: third_party/requests/cookies.py

Issue 25004007: Update 'requests' lib to v2.0. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/swarm_client
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/requests/cookies.py
diff --git a/third_party/requests/cookies.py b/third_party/requests/cookies.py
index d759d0a977f5f7c5c7d2c5fcb2e51543f868cf02..f3ac64f0a3aabe3bf778dbc64d23868f8bf416e9 100644
--- a/third_party/requests/cookies.py
+++ b/third_party/requests/cookies.py
@@ -6,6 +6,7 @@ Compatibility code to be able to use `cookielib.CookieJar` with requests.
requests.utils imports from here, so be careful with imports.
"""
+import time
import collections
from .compat import cookielib, urlparse, Morsel
@@ -73,6 +74,10 @@ class MockRequest(object):
def origin_req_host(self):
return self.get_origin_req_host()
+ @property
+ def host(self):
+ return self.get_host()
+
class MockResponse(object):
"""Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.
@@ -102,6 +107,9 @@ def extract_cookies_to_jar(jar, request, response):
:param request: our own requests.Request object
:param response: urllib3.HTTPResponse object
"""
+ if not (hasattr(response, '_original_response') and
+ response._original_response):
+ return
# the _original_response field is the wrapped httplib.HTTPResponse object,
req = MockRequest(request)
# pull out the HTTPMessage with the headers and put it in the mock:
@@ -258,6 +266,11 @@ 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 set_cookie(self, cookie, *args, **kwargs):
+ if cookie.value.startswith('"') and cookie.value.endswith('"'):
+ cookie.value = cookie.value.replace('\\"', '')
+ return super(RequestsCookieJar, self).set_cookie(cookie, *args, **kwargs)
+
def update(self, other):
"""Updates this jar with cookies from another CookieJar or dict-like"""
if isinstance(other, cookielib.CookieJar):
@@ -354,19 +367,23 @@ def create_cookie(name, value, **kwargs):
def morsel_to_cookie(morsel):
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
+ expires = None
+ if morsel["max-age"]:
+ expires = time.time() + morsel["max-age"]
+ elif morsel['expires']:
+ expires = morsel['expires']
+ if type(expires) == type(""):
+ time_template = "%a, %d-%b-%Y %H:%M:%S GMT"
+ expires = time.mktime(time.strptime(expires, time_template))
c = create_cookie(
name=morsel.key,
value=morsel.value,
version=morsel['version'] or 0,
port=None,
- port_specified=False,
domain=morsel['domain'],
- domain_specified=bool(morsel['domain']),
- domain_initial_dot=morsel['domain'].startswith('.'),
path=morsel['path'],
- path_specified=bool(morsel['path']),
secure=bool(morsel['secure']),
- expires=morsel['max-age'] or morsel['expires'],
+ expires=expires,
discard=False,
comment=morsel['comment'],
comment_url=bool(morsel['comment']),

Powered by Google App Engine
This is Rietveld 408576698