~ubuntu-branches/ubuntu/utopic/requests/utopic

« back to all changes in this revision

Viewing changes to requests/cookies.py

  • Committer: Package Import Robot
  • Author(s): Daniele Tricoli
  • Date: 2013-10-18 19:20:21 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20131018192021-hzbd8k13wgx2z8am
Tags: 2.0.0-1
* New upstream release (Closes: #725784)
* Switched to pybuild
* debian/clean
  - Switched to debian/clean for cleaning instead of using debian/rules
* debian/control
  - Bumped python(3)-urllib3 to (>=1.7.1)
* debian/copyright
  - Updated copyright year
* debian/patches/02_use-system-chardet-and-urllib3.patches
  - Refreshed
* debian/watch
  - Switched download URL to https

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
requests.utils imports from here, so be careful with imports.
7
7
"""
8
8
 
 
9
import time
9
10
import collections
10
11
from .compat import cookielib, urlparse, Morsel
11
12
 
73
74
    def origin_req_host(self):
74
75
        return self.get_origin_req_host()
75
76
 
 
77
    @property
 
78
    def host(self):
 
79
        return self.get_host()
 
80
 
76
81
 
77
82
class MockResponse(object):
78
83
    """Wraps a `httplib.HTTPMessage` to mimic a `urllib.addinfourl`.
102
107
    :param request: our own requests.Request object
103
108
    :param response: urllib3.HTTPResponse object
104
109
    """
 
110
    if not (hasattr(response, '_original_response') and
 
111
            response._original_response):
 
112
        return
105
113
    # the _original_response field is the wrapped httplib.HTTPResponse object,
106
114
    req = MockRequest(request)
107
115
    # pull out the HTTPMessage with the headers and put it in the mock:
258
266
        """Deletes a cookie given a name. Wraps cookielib.CookieJar's remove_cookie_by_name()."""
259
267
        remove_cookie_by_name(self, name)
260
268
 
 
269
    def set_cookie(self, cookie, *args, **kwargs):
 
270
        if cookie.value.startswith('"') and cookie.value.endswith('"'):
 
271
            cookie.value = cookie.value.replace('\\"', '')
 
272
        return super(RequestsCookieJar, self).set_cookie(cookie, *args, **kwargs)
 
273
 
261
274
    def update(self, other):
262
275
        """Updates this jar with cookies from another CookieJar or dict-like"""
263
276
        if isinstance(other, cookielib.CookieJar):
354
367
 
355
368
def morsel_to_cookie(morsel):
356
369
    """Convert a Morsel object into a Cookie containing the one k/v pair."""
 
370
    expires = None
 
371
    if morsel["max-age"]:
 
372
        expires = time.time() + morsel["max-age"]
 
373
    elif morsel['expires']:
 
374
        expires = morsel['expires']
 
375
        if type(expires) == type(""):
 
376
            time_template = "%a, %d-%b-%Y %H:%M:%S GMT"
 
377
            expires = time.mktime(time.strptime(expires, time_template))
357
378
    c = create_cookie(
358
379
        name=morsel.key,
359
380
        value=morsel.value,
360
381
        version=morsel['version'] or 0,
361
382
        port=None,
362
 
        port_specified=False,
363
383
        domain=morsel['domain'],
364
 
        domain_specified=bool(morsel['domain']),
365
 
        domain_initial_dot=morsel['domain'].startswith('.'),
366
384
        path=morsel['path'],
367
 
        path_specified=bool(morsel['path']),
368
385
        secure=bool(morsel['secure']),
369
 
        expires=morsel['max-age'] or morsel['expires'],
 
386
        expires=expires,
370
387
        discard=False,
371
388
        comment=morsel['comment'],
372
389
        comment_url=bool(morsel['comment']),