aboutsummaryrefslogtreecommitdiffhomepage
path: root/libs/requests
diff options
context:
space:
mode:
authorpanni <[email protected]>2018-10-31 17:08:29 +0100
committerpanni <[email protected]>2018-10-31 17:08:29 +0100
commit8f584143f8afc46a75a83dab5243739772e3562b (patch)
treec7dae21e993880af8bee71ad7b5a63f2977db577 /libs/requests
parent4beaeaa99e84bbe1ed87d0466a55a22ba25c8437 (diff)
downloadbazarr-8f584143f8afc46a75a83dab5243739772e3562b.tar.gz
bazarr-8f584143f8afc46a75a83dab5243739772e3562b.zip
update deps
Diffstat (limited to 'libs/requests')
-rw-r--r--libs/requests/__init__.py17
-rw-r--r--libs/requests/__version__.py4
-rw-r--r--libs/requests/adapters.py27
-rw-r--r--libs/requests/api.py20
-rw-r--r--libs/requests/auth.py4
-rw-r--r--libs/requests/compat.py3
-rw-r--r--libs/requests/cookies.py31
-rw-r--r--libs/requests/help.py3
-rw-r--r--libs/requests/hooks.py4
-rw-r--r--libs/requests/models.py17
-rw-r--r--libs/requests/sessions.py52
-rw-r--r--libs/requests/status_codes.py2
-rw-r--r--libs/requests/utils.py19
13 files changed, 114 insertions, 89 deletions
diff --git a/libs/requests/__init__.py b/libs/requests/__init__.py
index a5b3c9c33..bc168ee53 100644
--- a/libs/requests/__init__.py
+++ b/libs/requests/__init__.py
@@ -22,7 +22,7 @@ usage:
... or POST:
>>> payload = dict(key1='value1', key2='value2')
- >>> r = requests.post('http://httpbin.org/post', data=payload)
+ >>> r = requests.post('https://httpbin.org/post', data=payload)
>>> print(r.text)
{
...
@@ -57,10 +57,10 @@ def check_compatibility(urllib3_version, chardet_version):
# Check urllib3 for compatibility.
major, minor, patch = urllib3_version # noqa: F811
major, minor, patch = int(major), int(minor), int(patch)
- # urllib3 >= 1.21.1, <= 1.23
+ # urllib3 >= 1.21.1, <= 1.24
assert major == 1
assert minor >= 21
- assert minor <= 23
+ assert minor <= 24
# Check chardet for compatibility.
major, minor, patch = chardet_version.split('.')[:3]
@@ -79,14 +79,14 @@ def _check_cryptography(cryptography_version):
return
if cryptography_version < [1, 3, 4]:
- warning = 'Old version of cryptography ({0}) may cause slowdown.'.format(cryptography_version)
+ warning = 'Old version of cryptography ({}) may cause slowdown.'.format(cryptography_version)
warnings.warn(warning, RequestsDependencyWarning)
# Check imported dependencies for compatibility.
try:
check_compatibility(urllib3.__version__, chardet.__version__)
except (AssertionError, ValueError):
- warnings.warn("urllib3 ({0}) or chardet ({1}) doesn't match a supported "
+ warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
"version!".format(urllib3.__version__, chardet.__version__),
RequestsDependencyWarning)
@@ -123,12 +123,7 @@ from .exceptions import (
# Set default logging handler to avoid "No handler found" warnings.
import logging
-try: # Python 2.7+
- from logging import NullHandler
-except ImportError:
- class NullHandler(logging.Handler):
- def emit(self, record):
- pass
+from logging import NullHandler
logging.getLogger(__name__).addHandler(NullHandler())
diff --git a/libs/requests/__version__.py b/libs/requests/__version__.py
index ef61ec0f5..be8a45fe0 100644
--- a/libs/requests/__version__.py
+++ b/libs/requests/__version__.py
@@ -5,8 +5,8 @@
__title__ = 'requests'
__description__ = 'Python HTTP for Humans.'
__url__ = 'http://python-requests.org'
-__version__ = '2.19.1'
-__build__ = 0x021901
+__version__ = '2.20.0'
+__build__ = 0x022000
__author__ = 'Kenneth Reitz'
__author_email__ = '[email protected]'
__license__ = 'Apache 2.0'
diff --git a/libs/requests/adapters.py b/libs/requests/adapters.py
index a4b028420..fa4d9b3cc 100644
--- a/libs/requests/adapters.py
+++ b/libs/requests/adapters.py
@@ -26,6 +26,7 @@ from urllib3.exceptions import ProtocolError
from urllib3.exceptions import ReadTimeoutError
from urllib3.exceptions import SSLError as _SSLError
from urllib3.exceptions import ResponseError
+from urllib3.exceptions import LocationValueError
from .models import Response
from .compat import urlparse, basestring
@@ -35,7 +36,8 @@ from .utils import (DEFAULT_CA_BUNDLE_PATH, extract_zipped_paths,
from .structures import CaseInsensitiveDict
from .cookies import extract_cookies_to_jar
from .exceptions import (ConnectionError, ConnectTimeout, ReadTimeout, SSLError,
- ProxyError, RetryError, InvalidSchema, InvalidProxyURL)
+ ProxyError, RetryError, InvalidSchema, InvalidProxyURL,
+ InvalidURL)
from .auth import _basic_auth_str
try:
@@ -127,8 +129,7 @@ class HTTPAdapter(BaseAdapter):
self.init_poolmanager(pool_connections, pool_maxsize, block=pool_block)
def __getstate__(self):
- return dict((attr, getattr(self, attr, None)) for attr in
- self.__attrs__)
+ return {attr: getattr(self, attr, None) for attr in self.__attrs__}
def __setstate__(self, state):
# Can't handle by adding 'proxy_manager' to self.__attrs__ because
@@ -224,7 +225,7 @@ class HTTPAdapter(BaseAdapter):
if not cert_loc or not os.path.exists(cert_loc):
raise IOError("Could not find a suitable TLS CA certificate bundle, "
- "invalid path: {0}".format(cert_loc))
+ "invalid path: {}".format(cert_loc))
conn.cert_reqs = 'CERT_REQUIRED'
@@ -246,10 +247,10 @@ class HTTPAdapter(BaseAdapter):
conn.key_file = None
if conn.cert_file and not os.path.exists(conn.cert_file):
raise IOError("Could not find the TLS certificate file, "
- "invalid path: {0}".format(conn.cert_file))
+ "invalid path: {}".format(conn.cert_file))
if conn.key_file and not os.path.exists(conn.key_file):
raise IOError("Could not find the TLS key file, "
- "invalid path: {0}".format(conn.key_file))
+ "invalid path: {}".format(conn.key_file))
def build_response(self, req, resp):
"""Builds a :class:`Response <requests.Response>` object from a urllib3
@@ -378,7 +379,7 @@ class HTTPAdapter(BaseAdapter):
when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
- :param proxies: The url of the proxy being used for this request.
+ :param proxy: The url of the proxy being used for this request.
:rtype: dict
"""
headers = {}
@@ -407,7 +408,10 @@ class HTTPAdapter(BaseAdapter):
:rtype: requests.Response
"""
- conn = self.get_connection(request.url, proxies)
+ try:
+ conn = self.get_connection(request.url, proxies)
+ except LocationValueError as e:
+ raise InvalidURL(e, request=request)
self.cert_verify(conn, request.url, verify, cert)
url = self.request_url(request, proxies)
@@ -421,7 +425,7 @@ class HTTPAdapter(BaseAdapter):
timeout = TimeoutSauce(connect=connect, read=read)
except ValueError as e:
# this may raise a string formatting error.
- err = ("Invalid timeout {0}. Pass a (connect, read) "
+ err = ("Invalid timeout {}. Pass a (connect, read) "
"timeout tuple, or a single float to set "
"both timeouts to the same value".format(timeout))
raise ValueError(err)
@@ -471,11 +475,10 @@ class HTTPAdapter(BaseAdapter):
# Receive the response from the server
try:
- # For Python 2.7+ versions, use buffering of HTTP
- # responses
+ # For Python 2.7, use buffering of HTTP responses
r = low_conn.getresponse(buffering=True)
except TypeError:
- # For compatibility with Python 2.6 versions and back
+ # For compatibility with Python 3.3+
r = low_conn.getresponse()
resp = HTTPResponse.from_httplib(
diff --git a/libs/requests/api.py b/libs/requests/api.py
index a2cc84d76..abada96d4 100644
--- a/libs/requests/api.py
+++ b/libs/requests/api.py
@@ -18,8 +18,10 @@ def request(method, url, **kwargs):
:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
- :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
- :param data: (optional) Dictionary or list of tuples ``[(key, value)]`` (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
+ :param params: (optional) Dictionary, list of tuples or bytes to send
+ in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.
:param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.
@@ -47,7 +49,7 @@ def request(method, url, **kwargs):
Usage::
>>> import requests
- >>> req = requests.request('GET', 'http://httpbin.org/get')
+ >>> req = requests.request('GET', 'https://httpbin.org/get')
<Response [200]>
"""
@@ -62,7 +64,8 @@ def get(url, params=None, **kwargs):
r"""Sends a GET request.
:param url: URL for the new :class:`Request` object.
- :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
+ :param params: (optional) Dictionary, list of tuples or bytes to send
+ in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
:rtype: requests.Response
@@ -102,7 +105,8 @@ def post(url, data=None, json=None, **kwargs):
r"""Sends a POST request.
:param url: URL for the new :class:`Request` object.
- :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
@@ -116,7 +120,8 @@ def put(url, data=None, **kwargs):
r"""Sends a PUT request.
:param url: URL for the new :class:`Request` object.
- :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
@@ -130,7 +135,8 @@ def patch(url, data=None, **kwargs):
r"""Sends a PATCH request.
:param url: URL for the new :class:`Request` object.
- :param data: (optional) Dictionary (will be form-encoded), bytes, or file-like object to send in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param json: (optional) json data to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:return: :class:`Response <Response>` object
diff --git a/libs/requests/auth.py b/libs/requests/auth.py
index 4ae459474..bdde51c7f 100644
--- a/libs/requests/auth.py
+++ b/libs/requests/auth.py
@@ -38,7 +38,7 @@ def _basic_auth_str(username, password):
if not isinstance(username, basestring):
warnings.warn(
"Non-string usernames will no longer be supported in Requests "
- "3.0.0. Please convert the object you've passed in ({0!r}) to "
+ "3.0.0. Please convert the object you've passed in ({!r}) to "
"a string or bytes object in the near future to avoid "
"problems.".format(username),
category=DeprecationWarning,
@@ -48,7 +48,7 @@ def _basic_auth_str(username, password):
if not isinstance(password, basestring):
warnings.warn(
"Non-string passwords will no longer be supported in Requests "
- "3.0.0. Please convert the object you've passed in ({0!r}) to "
+ "3.0.0. Please convert the object you've passed in ({!r}) to "
"a string or bytes object in the near future to avoid "
"problems.".format(password),
category=DeprecationWarning,
diff --git a/libs/requests/compat.py b/libs/requests/compat.py
index 6b9c6facb..c44b35efb 100644
--- a/libs/requests/compat.py
+++ b/libs/requests/compat.py
@@ -43,9 +43,8 @@ if is_py2:
import cookielib
from Cookie import Morsel
from StringIO import StringIO
- from collections import Callable, Mapping, MutableMapping
+ from collections import Callable, Mapping, MutableMapping, OrderedDict
- from urllib3.packages.ordered_dict import OrderedDict
builtin_str = str
bytes = str
diff --git a/libs/requests/cookies.py b/libs/requests/cookies.py
index 50883a84f..56fccd9c2 100644
--- a/libs/requests/cookies.py
+++ b/libs/requests/cookies.py
@@ -444,20 +444,21 @@ def create_cookie(name, value, **kwargs):
By default, the pair of `name` and `value` will be set for the domain ''
and sent on every request (this is sometimes called a "supercookie").
"""
- result = dict(
- version=0,
- name=name,
- value=value,
- port=None,
- domain='',
- path='/',
- secure=False,
- expires=None,
- discard=True,
- comment=None,
- comment_url=None,
- rest={'HttpOnly': None},
- rfc2109=False,)
+ result = {
+ 'version': 0,
+ 'name': name,
+ 'value': value,
+ 'port': None,
+ 'domain': '',
+ 'path': '/',
+ 'secure': False,
+ 'expires': None,
+ 'discard': True,
+ 'comment': None,
+ 'comment_url': None,
+ 'rest': {'HttpOnly': None},
+ 'rfc2109': False,
+ }
badargs = set(kwargs) - set(result)
if badargs:
@@ -511,6 +512,7 @@ def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
:param cookiejar: (optional) A cookiejar to add the cookies to.
:param overwrite: (optional) If False, will not replace cookies
already in the jar with new ones.
+ :rtype: CookieJar
"""
if cookiejar is None:
cookiejar = RequestsCookieJar()
@@ -529,6 +531,7 @@ def merge_cookies(cookiejar, cookies):
:param cookiejar: CookieJar object to add the cookies to.
:param cookies: Dictionary or CookieJar object to be added.
+ :rtype: CookieJar
"""
if not isinstance(cookiejar, cookielib.CookieJar):
raise ValueError('You can only merge into CookieJar')
diff --git a/libs/requests/help.py b/libs/requests/help.py
index 06e06b2a7..e53d35ef6 100644
--- a/libs/requests/help.py
+++ b/libs/requests/help.py
@@ -89,8 +89,7 @@ def info():
'version': getattr(idna, '__version__', ''),
}
- # OPENSSL_VERSION_NUMBER doesn't exist in the Python 2.6 ssl module.
- system_ssl = getattr(ssl, 'OPENSSL_VERSION_NUMBER', None)
+ system_ssl = ssl.OPENSSL_VERSION_NUMBER
system_ssl_info = {
'version': '%x' % system_ssl if system_ssl is not None else ''
}
diff --git a/libs/requests/hooks.py b/libs/requests/hooks.py
index 32b32de75..7a51f212c 100644
--- a/libs/requests/hooks.py
+++ b/libs/requests/hooks.py
@@ -15,14 +15,14 @@ HOOKS = ['response']
def default_hooks():
- return dict((event, []) for event in HOOKS)
+ return {event: [] for event in HOOKS}
# TODO: response is the only one
def dispatch_hook(key, hooks, hook_data, **kwargs):
"""Dispatches a hook dictionary on a given piece of data."""
- hooks = hooks or dict()
+ hooks = hooks or {}
hooks = hooks.get(key)
if hooks:
if hasattr(hooks, '__call__'):
diff --git a/libs/requests/models.py b/libs/requests/models.py
index 3d0e1f42a..3dded57ef 100644
--- a/libs/requests/models.py
+++ b/libs/requests/models.py
@@ -204,9 +204,13 @@ class Request(RequestHooksMixin):
:param url: URL to send.
:param headers: dictionary of headers to send.
:param files: dictionary of {filename: fileobject} files to multipart upload.
- :param data: the body to attach to the request. If a dictionary is provided, form-encoding will take place.
+ :param data: the body to attach to the request. If a dictionary or
+ list of tuples ``[(key, value)]`` is provided, form-encoding will
+ take place.
:param json: json for the body to attach to the request (if files or data is not specified).
- :param params: dictionary of URL parameters to append to the URL.
+ :param params: URL parameters to append to the URL. If a dictionary or
+ list of tuples ``[(key, value)]`` is provided, form-encoding will
+ take place.
:param auth: Auth handler or (user, pass) tuple.
:param cookies: dictionary or CookieJar of cookies to attach to this request.
:param hooks: dictionary of callback hooks, for internal usage.
@@ -214,7 +218,7 @@ class Request(RequestHooksMixin):
Usage::
>>> import requests
- >>> req = requests.Request('GET', 'http://httpbin.org/get')
+ >>> req = requests.Request('GET', 'https://httpbin.org/get')
>>> req.prepare()
<PreparedRequest [GET]>
"""
@@ -274,7 +278,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
Usage::
>>> import requests
- >>> req = requests.Request('GET', 'http://httpbin.org/get')
+ >>> req = requests.Request('GET', 'https://httpbin.org/get')
>>> r = req.prepare()
<PreparedRequest [GET]>
@@ -648,10 +652,7 @@ class Response(object):
if not self._content_consumed:
self.content
- return dict(
- (attr, getattr(self, attr, None))
- for attr in self.__attrs__
- )
+ return {attr: getattr(self, attr, None) for attr in self.__attrs__}
def __setstate__(self, state):
for name, value in state.items():
diff --git a/libs/requests/sessions.py b/libs/requests/sessions.py
index ba135268a..a448bd83f 100644
--- a/libs/requests/sessions.py
+++ b/libs/requests/sessions.py
@@ -115,6 +115,22 @@ class SessionRedirectMixin(object):
return to_native_string(location, 'utf8')
return None
+ def should_strip_auth(self, old_url, new_url):
+ """Decide whether Authorization header should be removed when redirecting"""
+ old_parsed = urlparse(old_url)
+ new_parsed = urlparse(new_url)
+ if old_parsed.hostname != new_parsed.hostname:
+ return True
+ # Special case: allow http -> https redirect when using the standard
+ # ports. This isn't specified by RFC 7235, but is kept to avoid
+ # breaking backwards compatibility with older versions of requests
+ # that allowed any redirects on the same host.
+ if (old_parsed.scheme == 'http' and old_parsed.port in (80, None)
+ and new_parsed.scheme == 'https' and new_parsed.port in (443, None)):
+ return False
+ # Standard case: root URI must match
+ return old_parsed.port != new_parsed.port or old_parsed.scheme != new_parsed.scheme
+
def resolve_redirects(self, resp, req, stream=False, timeout=None,
verify=True, cert=None, proxies=None, yield_requests=False, **adapter_kwargs):
"""Receives a Response. Returns a generator of Responses or Requests."""
@@ -236,14 +252,10 @@ class SessionRedirectMixin(object):
headers = prepared_request.headers
url = prepared_request.url
- if 'Authorization' in headers:
+ if 'Authorization' in headers and self.should_strip_auth(response.request.url, url):
# If we get redirected to a new host, we should strip out any
# authentication headers.
- original_parsed = urlparse(response.request.url)
- redirect_parsed = urlparse(url)
-
- if (original_parsed.hostname != redirect_parsed.hostname):
- del headers['Authorization']
+ del headers['Authorization']
# .netrc might have more auth for us on our new host.
new_auth = get_netrc_auth(url) if self.trust_env else None
@@ -299,7 +311,7 @@ class SessionRedirectMixin(object):
"""
method = prepared_request.method
- # http://tools.ietf.org/html/rfc7231#section-6.4.4
+ # https://tools.ietf.org/html/rfc7231#section-6.4.4
if response.status_code == codes.see_other and method != 'HEAD':
method = 'GET'
@@ -325,13 +337,13 @@ class Session(SessionRedirectMixin):
>>> import requests
>>> s = requests.Session()
- >>> s.get('http://httpbin.org/get')
+ >>> s.get('https://httpbin.org/get')
<Response [200]>
Or as a context manager::
>>> with requests.Session() as s:
- >>> s.get('http://httpbin.org/get')
+ >>> s.get('https://httpbin.org/get')
<Response [200]>
"""
@@ -453,8 +465,8 @@ class Session(SessionRedirectMixin):
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query
string for the :class:`Request`.
- :param data: (optional) Dictionary, bytes, or file-like object to send
- in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param json: (optional) json to send in the body of the
:class:`Request`.
:param headers: (optional) Dictionary of HTTP Headers to send with the
@@ -550,7 +562,8 @@ class Session(SessionRedirectMixin):
r"""Sends a POST request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
- :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param json: (optional) json to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
@@ -562,7 +575,8 @@ class Session(SessionRedirectMixin):
r"""Sends a PUT request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
- :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
"""
@@ -573,7 +587,8 @@ class Session(SessionRedirectMixin):
r"""Sends a PATCH request. Returns :class:`Response` object.
:param url: URL for the new :class:`Request` object.
- :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`.
+ :param data: (optional) Dictionary, list of tuples, bytes, or file-like
+ object to send in the body of the :class:`Request`.
:param \*\*kwargs: Optional arguments that ``request`` takes.
:rtype: requests.Response
"""
@@ -723,7 +738,7 @@ class Session(SessionRedirectMixin):
self.adapters[key] = self.adapters.pop(key)
def __getstate__(self):
- state = dict((attr, getattr(self, attr, None)) for attr in self.__attrs__)
+ state = {attr: getattr(self, attr, None) for attr in self.__attrs__}
return state
def __setstate__(self, state):
@@ -735,7 +750,12 @@ def session():
"""
Returns a :class:`Session` for context-management.
+ .. deprecated:: 1.0.0
+
+ This method has been deprecated since version 1.0.0 and is only kept for
+ backwards compatibility. New code should use :class:`~requests.sessions.Session`
+ to create a session. This may be removed at a future date.
+
:rtype: Session
"""
-
return Session()
diff --git a/libs/requests/status_codes.py b/libs/requests/status_codes.py
index ff462c6c6..813e8c4e6 100644
--- a/libs/requests/status_codes.py
+++ b/libs/requests/status_codes.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
-"""
+r"""
The ``codes`` object defines a mapping from common names for HTTP statuses
to their numerical codes, accessible either as attributes or as dictionary
items.
diff --git a/libs/requests/utils.py b/libs/requests/utils.py
index 431f6be07..0ce7fe115 100644
--- a/libs/requests/utils.py
+++ b/libs/requests/utils.py
@@ -173,10 +173,10 @@ def get_netrc_auth(url, raise_errors=False):
for f in NETRC_FILES:
try:
- loc = os.path.expanduser('~/{0}'.format(f))
+ loc = os.path.expanduser('~/{}'.format(f))
except KeyError:
# os.path.expanduser can fail when $HOME is undefined and
- # getpwuid fails. See http://bugs.python.org/issue20164 &
+ # getpwuid fails. See https://bugs.python.org/issue20164 &
# https://github.com/requests/requests/issues/1846
return
@@ -466,7 +466,7 @@ def _parse_content_type_header(header):
if index_of_equals != -1:
key = param[:index_of_equals].strip(items_to_strip)
value = param[index_of_equals + 1:].strip(items_to_strip)
- params_dict[key] = value
+ params_dict[key.lower()] = value
return content_type, params_dict
@@ -706,6 +706,10 @@ def should_bypass_proxies(url, no_proxy):
no_proxy = get_proxy('no_proxy')
parsed = urlparse(url)
+ if parsed.hostname is None:
+ # URLs don't always have hostnames, e.g. file:/// urls.
+ return True
+
if no_proxy:
# We need to check whether we match here. We need to see if we match
# the end of the hostname, both with and without the port.
@@ -725,7 +729,7 @@ def should_bypass_proxies(url, no_proxy):
else:
host_with_port = parsed.hostname
if parsed.port:
- host_with_port += ':{0}'.format(parsed.port)
+ host_with_port += ':{}'.format(parsed.port)
for host in no_proxy:
if parsed.hostname.endswith(host) or host_with_port.endswith(host):
@@ -733,13 +737,8 @@ def should_bypass_proxies(url, no_proxy):
# to apply the proxies on this URL.
return True
- # If the system proxy settings indicate that this URL should be bypassed,
- # don't proxy.
- # The proxy_bypass function is incredibly buggy on OS X in early versions
- # of Python 2.6, so allow this call to fail. Only catch the specific
- # exceptions we've seen, though: this call failing in other ways can reveal
- # legitimate problems.
with set_environ('no_proxy', no_proxy_arg):
+ # parsed.hostname can be `None` in cases such as a file URI.
try:
bypass = proxy_bypass(parsed.hostname)
except (TypeError, socket.gaierror):