Skip to content
Myr

Fail if unsupported schemas are used.

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

requests only supports http and https. This change enforces that.

authored by Cory Benfield · committed by Cory Benfield · parent 1ded0ad · Browse files · 3 files+16 added−9 removed
This commit

State

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

Diff stats

3 files+16 added−9 removed

  • tests:+5 added−8 removed
  • other:+11 added−1 removed

3 files+16 added−9 removed

modified:requests/models.py+4 added-1 removed
24 unmodified lines
25 ConnectionError, HTTPError, RequestException, Timeout, TooManyRedirects,26 URLRequired, SSLError)27from .utils import (28 get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,29 dict_from_string)29 dict_from_string, supported_schemes)3031from .compat import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, str, bytes, SimpleCookie, is_py3, is_py23233# Import chardet if it is available.
281 unmodified lines
315316 if not scheme:317 raise ValueError("Invalid URL %r: No schema supplied" % url)318319 if not scheme in supported_schemes():320 raise ValueError("Invalid scheme %r" % scheme)321322 netloc = netloc.encode('idna').decode('utf-8')323324 if not path:325 path = '/'
479 unmodified lines
modified:requests/utils.py+7 added
414 unmodified lines
415 # Then quote only illegal characters (do not quote reserved, unreserved,416 # or '%')417 return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")418 return "/".join(parts)419420def supported_schemes():421 """A list of schemes supported by requests.422423 return: a list of strings.424 """425 return ["http","https"]
modified:tests/test_requests.py+5 added-8 removed
813 unmodified lines
814 r = requests.get(httpbin('post'), auth=('a', 'b'), data='\xff')815816 def test_useful_exception_for_invalid_schema(self):817 818 try:819 self.assertRaises(820 requests.exceptions.URLRequired,818 # If we pass a legitimate URL with a schema not supported 819 # by requests, we should fail.820 self.assertRaises(821 ValueError,822 get,822 'http://http://')823 # To make this test as minimal as possible, only catch the824 # exception raised in issue #380.825 except ValueError:826 self.fail()823 'ftp://ftp.kernel.org/pub/')824825826827if __name__ == '__main__':
1 unmodified line