Merge branch 'issue_380' of https://github.com/Lukasa/requests into develop

This commit is contained in:
Kenneth Reitz
2012-02-20 12:11:31 -05:00
3 changed files with 20 additions and 1 deletions
+4 -1
View File
@@ -26,7 +26,7 @@ from .exceptions import (
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
@@ -316,6 +316,9 @@ class Request(object):
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:
+7
View File
@@ -416,3 +416,10 @@ def requote_uri(uri):
# 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"]
+9
View File
@@ -827,6 +827,15 @@ class RequestsTestSuite(TestSetup, unittest.TestCase):
r = requests.get(httpbin('post'), auth=('a', 'b'), data='\xff')
def test_useful_exception_for_invalid_scheme(self):
# If we pass a legitimate URL with a scheme not supported
# by requests, we should fail.
self.assertRaises(
ValueError,
get,
'ftp://ftp.kernel.org/pub/')
if __name__ == '__main__':