Merge branch 'develop' of https://github.com/jerem/requests into feature/jerem
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 · parents ce4927e, c22b71f · Browse files · 2 files·+30 added−7 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+30 added−7 removed
- other:+30 added−7 removed
Provenance
- Commit
9d143ed- Tree
ea7d2bb- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
ce4927e- Parent 2
c22b71f
2 files changed+30 added−7 removed
modified:requests/exceptions.py+3 added
19 unmodified lines20 """A valid URL is required to make a request."""21 22 class InvalidMethod(RequestException):23 """An inappropriate method was attempted."""24+25+class TooManyRedirects(RequestException):26+ """Too many redirects."""modified:requests/models.py+27 added-7 removed
19 unmodified lines20 from .structures import CaseInsensitiveDict21 from .packages.poster.encode import multipart_encode22 from .packages.poster.streaminghttp import register_openers, get_handlers23 from .utils import dict_from_cookiejar24-from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod24+from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects25 26 27 REDIRECT_STATI = (301, 302, 303, 307)28 144 unmodified lines173 174 try:175 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))176 response.read = resp.read177+ response._resp = resp177- response.close = resp.close178+ response._close = resp.close179 180 if self.cookiejar:181 182 response.cookies = dict_from_cookiejar(self.cookiejar)22 unmodified lines205 (r.status_code is 303) or206 (self.allow_redirects))207 ):208 209+ r.close()210+211+ if not len(history) < 30:212+ raise TooManyRedirects()213+214 history.append(r)215 216 url = r.headers['location']217 218+ # Handle redirection without scheme (see: RFC 1808 Section 4)219+ if url.startswith('//'):220+ parsed_rurl = urlparse(r.url)221+ url = '%s:%s' % (parsed_rurl.scheme, url)222+223 # Facilitate non-RFC2616-compliant 'location' headers224 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')214- url = urljoin(r.url, url)225+ if not urlparse(url).netloc:226+ url = urljoin(r.url, urllib.quote(urllib.unquote(url)))227 228 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4229 if r.status_code is 303:230 method = 'GET'39 unmodified lines270 271 def _build_url(self):272 """Build the actual URL to use."""273 262- # Support for unicode domain names.263- parsed_url = list(urlparse(self.url))264- parsed_url[1] = parsed_url[1].encode('idna')265- self.url = urlunparse(parsed_url)274+ # Support for unicode domain names and paths.275+ scheme, netloc, path, params, query, fragment = urlparse(self.url)276+ netloc = netloc.encode('idna')277+ if isinstance(path, unicode):278+ path = path.encode('utf-8')279+ path = urllib.quote(urllib.unquote(path))280+ self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))281 282 if self._enc_params:283 if urlparse(self.url).query:284 return '%s&%s' % (self.url, self._enc_params)154 unmodified lines439 if self.error:440 raise self.error441 442 443+ def close(self):444+ if self._resp.fp is not None and hasattr(self._resp.fp, '_sock'):445+ self._resp.fp._sock.recv = None446+ self._close()447+448 class AuthManager(object):449 """Requests Authentication Manager."""450 451 def __new__(cls):170 unmodified lines