Merge branch 'feature/jerem' into develop
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, abc5e27 · Browse files · 4 files·+37 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+37 added−11 removed
- other:+37 added−11 removed
Provenance
- Commit
e7d8982- Tree
52e2d40- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
ce4927e- Parent 2
abc5e27
4 files changed+37 added−11 removed
modified:requests/config.py+1 added
59 unmodified lines60 settings.accept_gzip = True61 settings.proxies = None62 settings.verbose = None63 settings.timeout = None64+settings.max_redirects = 3065 66 #: Use socket.setdefaulttimeout() as fallback?67 settings.timeout_fallback = Truemodified: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+32 added-10 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+from .status_codes import codes26 27 27-REDIRECT_STATI = (301, 302, 303, 307)28+REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)29 30 31+32 class Request(object):33 """The :class:`Request <models.Request>` object. It carries out all functionality of34 Requests. Recommended interface is with the Requests functions.35 """139 unmodified lines175 176 try:177 response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None))178 response.read = resp.read179+ response._resp = resp177- response.close = resp.close180+ response._close = resp.close181 182 if self.cookiejar:183 184 response.cookies = dict_from_cookiejar(self.cookiejar)18 unmodified lines203 204 while (205 ('location' in r.headers) and206 ((self.method in ('GET', 'HEAD')) or204- (r.status_code is 303) or207+ (r.status_code is codes.see_other) or208 (self.allow_redirects))209 ):210 211+ r.close()212+213+ if not len(history) < settings.max_redirects:214+ raise TooManyRedirects()215+216 history.append(r)217 218 url = r.headers['location']219 220+ # Handle redirection without scheme (see: RFC 1808 Section 4)221+ if url.startswith('//'):222+ parsed_rurl = urlparse(r.url)223+ url = '%s:%s' % (parsed_rurl.scheme, url)224+225 # Facilitate non-RFC2616-compliant 'location' headers226 # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource')214- url = urljoin(r.url, url)227+ if not urlparse(url).netloc:228+ url = urljoin(r.url, urllib.quote(urllib.unquote(url)))229 230 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4217- if r.status_code is 303:231+ if r.status_code is codes.see_other:232 method = 'GET'233 else:234 method = self.method235 36 unmodified lines272 273 def _build_url(self):274 """Build the actual URL to use."""275 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)276+ # Support for unicode domain names and paths.277+ scheme, netloc, path, params, query, fragment = urlparse(self.url)278+ netloc = netloc.encode('idna')279+ if isinstance(path, unicode):280+ path = path.encode('utf-8')281+ path = urllib.quote(urllib.unquote(path))282+ self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))283 284 if self._enc_params:285 if urlparse(self.url).query:286 return '%s&%s' % (self.url, self._enc_params)154 unmodified lines441 if self.error:442 raise self.error443 444 445+ def close(self):446+ if self._resp.fp is not None and hasattr(self._resp.fp, '_sock'):447+ self._resp.fp._sock.recv = None448+ self._close()449+450 class AuthManager(object):451 """Requests Authentication Manager."""452 453 def __new__(cls):170 unmodified linesmodified:requests/status_codes.py+1 added-1 removed
22 unmodified lines23 # Redirection.24 300: ('multiple_choices',),25 301: ('moved_permanently', 'moved', '\\o-'),26 302: ('found',),27- 302: ('see_other', 'other'),27+ 303: ('see_other', 'other'),28 304: ('not_modified',),29 305: ('use_proxy',),30 306: ('switch_proxy',),31 307: ('temporary_redirect', 'temporary_moved', 'temporary'),52 unmodified lines