serious commenting
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 7f3f641 · Browse files · 1 file·+27 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+27 added−4 removed
- other:+27 added−4 removed
Provenance
- Commit
332f55e- Tree
4ff0045- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
7f3f641
1 file changed+27 added−4 removed
modified:requests/models.py+27 added-4 removed
200 unmodified lines201 202 return response203 204 205+ # Request collector.206 history = []207 207-208+ # Create the lone response object.209 r = build(resp)210+211+ # Store the HTTP response, just in case.212 r._response = resp213 214+ # It's a redirect, and we're not already in a redirect loop.215 if r.status_code in REDIRECT_STATI and not self.redirect:216 217 while (218+ # There's a `Location` header.219 ('location' in r.headers) and220+221+ # See other response.222 ((r.status_code is codes.see_other) or223+224+ # Opt-in to redirects for non- idempotent methods.225 (self.allow_redirects))226 ):227 228+ # We already redirected. Don't keep it alive.229 r.raw.close()230 231+ # Woah, this is getting crazy.221- if not len(history) < settings.max_redirects:232+ if len(history) >= settings.max_redirects:233 raise TooManyRedirects()234 235+ # Add the old request to the history collector.236 history.append(r)237 238+ # Redirect to...239 url = r.headers['location']240 241 # Handle redirection without scheme (see: RFC 1808 Section 4)242 if url.startswith('//'):7 unmodified lines250 parsed_url = list(parsed_url)251 parsed_url[2] = urllib.quote(parsed_url[2], safe="%/:=&?~#+!$,;'@()*[]")252 url = urljoin(r.url, str(urlunparse(parsed_url)))253 254+ # If 303, convert to idempotent GET.255 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4256 if r.status_code is codes.see_other:257 method = 'GET'258 else:259 method = self.method260 261+ # Create the new Request.262 request = Request(263 url, self.headers, self.files, method,264 self.data, self.params, self.auth, self.cookiejar,265+266+ # Flag as part of a redirect loop.267 redirect=True268 )269+270+ # Send her away!271 request.send()272 r = request.response273 274+ # Insert collected history.275 r.history = history276 277+ # Attach Response to Request.278 self.response = r279+280+ # Give Response some context.281 self.response.request = self282 283 284 @staticmethod81 unmodified lines366 # Only send the Request if new or forced.367 if (anyway) or (not self.sent):368 369 try:347-370 # Create a new HTTP connection, since one wasn't passed in.371 if not connection:372 connection = urllib3.connection_from_url(url,373 timeout=self.timeout)374 375 # One-off request. Delay fetching the content until needed.376 do_block = False377 else:356- # Part of a connection pool, so no streaming. Sorry!378+ # Part of a connection pool, so no fancy stuff. Sorry!379 do_block = True380 381 # Create the connection.382 r = connection.urlopen(5 unmodified lines388 assert_same_host=False,389 block=do_block390 )391 392+ # Extract cookies.393 # if self.cookiejar is not None:394 # self.cookiejar.extract_cookies(resp, req)395 396 # except (urllib2.HTTPError, urllib2.URLError), why:407 unmodified lines