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:29 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:41:29 -0700
commit224200a9815f792f93632d03a38e4f0763ae69ef (patch)
tree161977259a7d8aa262aab60d7c8fce757ad3bb0f /requests/cookies.py
parent653256249d44c67a0852d57a166948a9dc712ef4 (diff)
downloadpython-requests-224200a9815f792f93632d03a38e4f0763ae69ef.tar
python-requests-224200a9815f792f93632d03a38e4f0763ae69ef.tar.gz
Imported Upstream version 2.0.0
Diffstat (limited to 'requests/cookies.py')
-rw-r--r--requests/cookies.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/requests/cookies.py b/requests/cookies.py
index d759d0a..f3ac64f 100644
--- a/requests/cookies.py
+++ b/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']),