Merge branch 'proxyscheme' of git://github.com/Lukasa/requests into 2.0
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 1a6637c, 840540b · Browse files · 2 files·+9 added−13 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+9 added−13 removed
- other:+9 added−13 removed
Provenance
- Commit
f865d61- Tree
134ee03- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
1a6637c- Parent 2
840540b
2 files changed+9 added−13 removed
modified:requests/adapters.py+2 added-2 removed
13 unmodified lines14 from .packages.urllib3.poolmanager import PoolManager, ProxyManager15 from .packages.urllib3.response import HTTPResponse16 from .compat import urlparse, basestring, urldefrag, unquote17 from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,18- prepend_scheme_if_needed, get_auth_from_url)18+ except_on_missing_scheme, get_auth_from_url)19 from .structures import CaseInsensitiveDict20 from .packages.urllib3.exceptions import MaxRetryError21 from .packages.urllib3.exceptions import TimeoutError22 from .packages.urllib3.exceptions import SSLError as _SSLError169 unmodified lines192 proxies = proxies or {}193 proxy = proxies.get(urlparse(url.lower()).scheme)194 195 if proxy:196- proxy = prepend_scheme_if_needed(proxy, urlparse(url.lower()).scheme)196+ except_on_missing_scheme(proxy)197 conn = ProxyManager(self.poolmanager.connection_from_url(proxy))198 else:199 conn = self.poolmanager.connection_from_url(url.lower())200 142 unmodified linesmodified:requests/utils.py+7 added-11 removed
23 unmodified lines24 from .compat import (quote, urlparse, bytes, str, OrderedDict, urlunparse,25 is_py2, is_py3, builtin_str, getproxies, proxy_bypass)26 from .cookies import RequestsCookieJar, cookiejar_from_dict27 from .structures import CaseInsensitiveDict28+from .exceptions import MissingSchema29 30 _hush_pyflakes = (RequestsCookieJar,)31 32 NETRC_FILES = ('.netrc', '_netrc')491 unmodified lines524 # Did not detect a valid UTF-32 ascii-range character525 return None526 527 527-def prepend_scheme_if_needed(url, new_scheme):528- '''Given a URL that may or may not have a scheme, prepend the given scheme.529- Does not replace a present scheme with the one provided as an argument.'''530- scheme, netloc, path, params, query, fragment = urlparse(url, new_scheme)528+def except_on_missing_scheme(url):529+ """Given a URL, raise a MissingSchema exception if the scheme is missing.530+ """531+ scheme, netloc, path, params, query, fragment = urlparse(url)532 532- # urlparse is a finicky beast, and sometimes decides that there isn't a533- # netloc present. Assume that it's being over-cautious, and switch netloc534- # and path if urlparse decided there was no netloc.535- if not netloc:536- netloc, path = path, netloc533+ if not scheme:534+ raise MissingSchema('Proxy URLs must have explicit schemes.')535 538- return urlunparse((scheme, netloc, path, params, query, fragment))536 540-537 def get_auth_from_url(url):538 """Given a url with authentication components, extract them into a tuple of539 username,password."""540 if url:23 unmodified lines