Skip to content
Myr

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

2 files+30 added−7 removed

modified:requests/exceptions.py+3 added
19 unmodified lines
20 """A valid URL is required to make a request."""2122class InvalidMethod(RequestException):23 """An inappropriate method was attempted."""2425class TooManyRedirects(RequestException):26 """Too many redirects."""
modified:requests/models.py+27 added-7 removed
19 unmodified lines
20from .structures import CaseInsensitiveDict21from .packages.poster.encode import multipart_encode22from .packages.poster.streaminghttp import register_openers, get_handlers23from .utils import dict_from_cookiejar24from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod24from .exceptions import RequestException, AuthenticationError, Timeout, URLRequired, InvalidMethod, TooManyRedirects252627REDIRECT_STATI = (301, 302, 303, 307)28
144 unmodified lines
173174 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.close179180 if self.cookiejar:181182 response.cookies = dict_from_cookiejar(self.cookiejar)
22 unmodified lines
205 (r.status_code is 303) or206 (self.allow_redirects))207 ):208209 r.close()210211 if not len(history) < 30:212 raise TooManyRedirects()213214 history.append(r)215216 url = r.headers['location']217218 # 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)222223 # 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)))227228 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4229 if r.status_code is 303:230 method = 'GET'
39 unmodified lines
270271 def _build_url(self):272 """Build the actual URL to use."""273262 # 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 ]))281282 if self._enc_params:283 if urlparse(self.url).query:284 return '%s&%s' % (self.url, self._enc_params)
154 unmodified lines
439 if self.error:440 raise self.error441442443 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()447448class AuthManager(object):449 """Requests Authentication Manager."""450451 def __new__(cls):
170 unmodified lines