Skip to content
Myr

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

1 file+27 added−4 removed

modified:requests/models.py+27 added-4 removed
200 unmodified lines
201202 return response203204205 # Request collector.206 history = []207207208 # Create the lone response object.209 r = build(resp)210211 # Store the HTTP response, just in case.212 r._response = resp213214 # 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:216217 while (218 # There's a `Location` header.219 ('location' in r.headers) and220221 # See other response.222 ((r.status_code is codes.see_other) or223224 # Opt-in to redirects for non- idempotent methods.225 (self.allow_redirects))226 ):227228 # We already redirected. Don't keep it alive.229 r.raw.close()230231 # Woah, this is getting crazy.221 if not len(history) < settings.max_redirects:232 if len(history) >= settings.max_redirects:233 raise TooManyRedirects()234235 # Add the old request to the history collector.236 history.append(r)237238 # Redirect to...239 url = r.headers['location']240241 # Handle redirection without scheme (see: RFC 1808 Section 4)242 if url.startswith('//'):
7 unmodified lines
250 parsed_url = list(parsed_url)251 parsed_url[2] = urllib.quote(parsed_url[2], safe="%/:=&?~#+!$,;'@()*[]")252 url = urljoin(r.url, str(urlunparse(parsed_url)))253254 # 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.method260261 # Create the new Request.262 request = Request(263 url, self.headers, self.files, method,264 self.data, self.params, self.auth, self.cookiejar,265266 # Flag as part of a redirect loop.267 redirect=True268 )269270 # Send her away!271 request.send()272 r = request.response273274 # Insert collected history.275 r.history = history276277 # Attach Response to Request.278 self.response = r279280 # Give Response some context.281 self.response.request = self282283284 @staticmethod
81 unmodified lines
366 # Only send the Request if new or forced.367 if (anyway) or (not self.sent):368369 try:347370 # 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)374375 # 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 = True380381 # Create the connection.382 r = connection.urlopen(
5 unmodified lines
388 assert_same_host=False,389 block=do_block390 )391392 # Extract cookies.393 # if self.cookiejar is not None:394 # self.cookiejar.extract_cookies(resp, req)395396 # except (urllib2.HTTPError, urllib2.URLError), why:
407 unmodified lines