URLRequired, SSLError)
from .utils import (
get_encoding_from_headers, stream_untransfer, guess_filename, requote_uri,
- dict_from_string)
+ dict_from_string, supported_schemes)
from .compat import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, str, bytes, SimpleCookie, is_py3, is_py2
if not scheme:
raise ValueError("Invalid URL %r: No schema supplied" % url)
+ if not scheme in supported_schemes():
+ raise ValueError("Invalid scheme %r" % scheme)
+
netloc = netloc.encode('idna').decode('utf-8')
if not path:
# or '%')
return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")
return "/".join(parts)
+
+def supported_schemes():
+ """A list of schemes supported by requests.
+
+ return: a list of strings.
+ """
+ return ["http","https"]
def test_useful_exception_for_invalid_schema(self):
- try:
- self.assertRaises(
- requests.exceptions.URLRequired,
+ # If we pass a legitimate URL with a schema not supported
+ # by requests, we should fail.
+ self.assertRaises(
+ ValueError,
get,
- 'http://http://')
- # To make this test as minimal as possible, only catch the
- # exception raised in issue #380.
- except ValueError:
- self.fail()
+ 'ftp://ftp.kernel.org/pub/')