Skip to content
Myr

yay cookies

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

authored by Kenneth Reitz · committed by Kenneth Reitz · parent 2f9e287 · Browse files · 3 files+43 added−5 removed
This commit

State

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

Diff stats

3 files+43 added−5 removed

  • other:+43 added−5 removed

3 files+43 added−5 removed

modified:requests/api.py+1 added-1 removed
47 unmodified lines
4849 if cookies is None:50 cookies = {}5152 cookies = cookiejar_from_dict(cookies)52 # cookies = cookiejar_from_dict(cookies)5354 # Expand header values55 if headers:56 for k, v in headers.items() or {}:
105 unmodified lines
modified:requests/models.py+40 added-2 removed
6 unmodified lines
7"""89import urllib10import zlib11from Cookie import SimpleCookie12from urlparse import urlparse, urlunparse, urljoin1314from .packages import urllib315from .packages.urllib3.filepost import encode_multipart_formdata
117 unmodified lines
133134 # Make headers case-insensitive.135 response.headers = CaseInsensitiveDict(getattr(resp, 'headers', None))136137 # Start off with our local cookies.138 cookies = self.cookies or dict()139140 # Add new cookies from the server.141 if 'set-cookie' in response.headers:142 cookie_header = response.headers['set-cookie']143144 c = SimpleCookie()145 c.load(cookie_header)146147 for k,v in c.items():148 cookies.update({k: v.value})149150 # Save cookies in Response.151 response.cookies = cookies152153 # Save original resopnse for later.154 response.raw = resp155156 # TODO: ?
99 unmodified lines
256257 # Build the final URL.258 url = build_url(self.url, self.params)259260 # Nottin' on you.261 body = None262 content_type = None263264 # Multi-part file uploads.
48 unmodified lines
313314 # Part of a connection pool, so no fancy stuff. Sorry!315 do_block = True316317 if self.cookies:318 # Skip if 'cookie' header is explicitly set.319 if 'cookie' not in self.headers:320321 # Simple cookie with our dict.322 c = SimpleCookie()323 c.load(self.cookies)324325 # Turn it into a header.326 cookie_header = c.output(header='').strip()327328 # Attach Cookie header to request.329 self.headers['Cookie'] = cookie_header330331 # Create the connection.332 r = connection.urlopen(333 method=self.method,334 url=url,
9 unmodified lines
344 if self.config.get('keepalive') and pools:345 self._pools = pools346347 # Extract cookies.316 # if self.cookiejar is not None:348 if self.cookies is not None:349 pass350 # cookies = cookiejar_from_dict(self.cookies)351# >>> C = Cookie.SimpleCookie()352# >>> C["rocky"] = "road"353# >>> C["rocky"]["path"] = "/cookie"354# >>> print C.output(header="Cookie:")355# Cookie: rocky=road; Path=/cookie356 # self.cookiejar.extract_cookies(resp, req)357358 # except (urllib2.HTTPError, urllib2.URLError), why:359 except Exception, why:
10 unmodified lines
370 # self.response = Response.from_urllib3()371 self._build_response(r)372 self.response.ok = True373335374 self.sent = self.response.ok375376 return self.sent377
131 unmodified lines
modified:requests/utils.py+2 added-2 removed
115 unmodified lines
116117 return ''.join(collector)118119120def dict_from_cookiejar(cj):120def dict_from_cookiejar(cookies):121 """Returns a key/value dictionary from a CookieJar.122123 :param cj: CookieJar object to extract cookies from.124 """125126 cookie_dict = {}127128 for _, cookies in cj._cookies.items():128 for _, cookies in cookies.items():129 for _, cookies in cookies.items():130 for cookie in cookies.values():131 cookie_dict[cookie.name] = cookie.value132
250 unmodified lines