Skip to content
Myr

get cookies from response

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

#116

authored by Kenneth Reitz · committed by Kenneth Reitz · parent b0a0b50 · Browse files · 2 files+32 added−0 removed
This commit

State

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

Diff stats

2 files+32 added−0 removed

  • other:+32 added−0 removed

2 files+32 added−0 removed

modified:requests/models.py+8 added
18 unmodified lines
19from .monkeys import Request as _Request, HTTPBasicAuthHandler, HTTPForcedBasicAuthHandler, HTTPDigestAuthHandler, HTTPRedirectHandler20from .structures import CaseInsensitiveDict21from .packages.poster.encode import multipart_encode22from .packages.poster.streaminghttp import register_openers, get_handlers23from .utils import dict_from_cookiejar24from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod252627REDIRECT_STATI = (301, 302, 303, 307)
159 unmodified lines
187 try:188 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))189 response.read = resp.read190 response.close = resp.close191192 if self.cookiejar:193194 response.cookies = dict_from_cookiejar(self.cookiejar)195196197 except AttributeError:198 pass199200 if is_error:
202 unmodified lines
403 #: up here.404 self.history = []405 #: The Request that created the Response.406 self.request = None407 self.cookies = None408409410 def __repr__(self):411 return '<Response [%s]>' % (self.status_code)
201 unmodified lines
added:requests/utils.py+24 added
1# -*- coding: utf-8 -*-23"""4requests.utils5~~~~~~~~~~~~~~67This module provides utlity functions that are used within Requests8that are also useful for external consumption.910"""111213def dict_from_cookiejar(cookiejar):14 """Returns a key/value dictoinary from a CookieJar."""1516 cookie_dict = {}1718 for _, cookies in cookiejar._cookies.items():19 for _, cookies in cookies.items():20 for cookie in cookies.values():21 cookie_dict[cookie.name] = cookie.value2223 return cookie_dict24