Skip to content
Myr

Merge pull request #4066 from kennethreitz/next

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

API improvements

authored by Kenneth Reitz · committed by GitHub · parents 60041f5, c3367d1 · Browse files · 2 files+36 added−20 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+36 added−20 removed

  • other:+36 added−20 removed

2 files+36 added−20 removed

modified:requests/models.py+8 added-2 removed
591 unmodified lines
592 super(Response, self).__init__()593594 self._content = False595 self._content_consumed = False596 self._next = None597598 #: Integer Code of responded HTTP Status, e.g. 404 or 200.599 self.status_code = None600
105 unmodified lines
706 return ('location' in self.headers and self.status_code in REDIRECT_STATI)707708 @property709 def is_permanent_redirect(self):709 """True if this Response one of the permanent versions of redirect"""710 """True if this Response one of the permanent versions of redirect."""711 return ('location' in self.headers and self.status_code in (codes.moved_permanently, codes.permanent_redirect))712713 @property714 def next(self):715 """Returns a PreparedRequest for the next request in a redirect chain, if there is one."""716 return self._next717718 @property719 def apparent_encoding(self):714 """The apparent encoding, provided by the chardet library"""720 """The apparent encoding, provided by the chardet library."""721 return chardet.detect(self.content)['encoding']722723 def iter_content(self, chunk_size=1, decode_unicode=False):724 """Iterates over the response data. When stream=True is set on the
223 unmodified lines
modified:requests/sessions.py+28 added-18 removed
112 unmodified lines
113 return to_native_string(location, 'utf8')114 return None115116 def resolve_redirects(self, resp, req, stream=False, timeout=None,117 verify=True, cert=None, proxies=None, **adapter_kwargs):118 """Receives a Response. Returns a generator of Responses."""117 verify=True, cert=None, proxies=None, yield_requests=False, **adapter_kwargs):118 """Receives a Response. Returns a generator of Responses or Requests."""119120 hist = [] # keep track of history121122 url = self.get_redirect_target(resp)
79 unmodified lines
202203 # Override the original request.204 req = prepared_request205206 resp = self.send(207 req,208 stream=stream,209 timeout=timeout,210 verify=verify,211 cert=cert,212 proxies=proxies,213 allow_redirects=False,214 **adapter_kwargs215 )206 if yield_requests:207 yield req208 else:209217 extract_cookies_to_jar(self.cookies, prepared_request, resp.raw)210 resp = self.send(211 req,212 stream=stream,213 timeout=timeout,214 verify=verify,215 cert=cert,216 proxies=proxies,217 allow_redirects=False,218 **adapter_kwargs219 )220219 # extract redirect url, if any, for the next loop220 url = self.get_redirect_target(resp)221 yield resp221 extract_cookies_to_jar(self.cookies, prepared_request, resp.raw)222223 # extract redirect url, if any, for the next loop224 url = self.get_redirect_target(resp)225 yield resp226227 def rebuild_auth(self, prepared_request, response):228 """When being redirected we may want to strip authentication from the229 request to avoid leaking credentials. This method intelligently removes230 and reapplies authentication where possible to avoid credential loss.
369 unmodified lines
600601 return self.request('DELETE', url, **kwargs)602603 def send(self, request, **kwargs):600 """601 Send a given PreparedRequest.604 """Send a given PreparedRequest.605606 :rtype: requests.Response607 """608 # Set defaults that the hooks can utilize to ensure they always have
61 unmodified lines
670 # Get the last request made671 r = history.pop()672 r.history = history673674 # If redirects aren't being followed, store the response on the Request for Response.next().675 if not allow_redirects:676 try:677 r._next = self.resolve_redirects(r, request, yield_requests=True, **kwargs).next()678 except StopIteration:679 pass680681 if not stream:682 r.content683684 return r
83 unmodified lines