diff options
Diffstat (limited to 'sphinx/util/requests.py')
-rw-r--r-- | sphinx/util/requests.py | 35 |
1 files changed, 7 insertions, 28 deletions
diff --git a/sphinx/util/requests.py b/sphinx/util/requests.py index 4b77a1169..dee52e281 100644 --- a/sphinx/util/requests.py +++ b/sphinx/util/requests.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ sphinx.util.requests ~~~~~~~~~~~~~~~~~~~~ @@ -9,15 +8,12 @@ :license: BSD, see LICENSE for details. """ -from __future__ import absolute_import - import warnings from contextlib import contextmanager +from urllib.parse import urlsplit import pkg_resources import requests -from six import string_types -from six.moves.urllib.parse import urlsplit try: from requests.packages.urllib3.exceptions import SSLError @@ -48,7 +44,7 @@ except ImportError: # try to load requests[security] (but only if SSL is available) try: - import ssl + import ssl # NOQA except ImportError: pass else: @@ -56,24 +52,7 @@ else: pkg_resources.require(['requests[security]']) except (pkg_resources.DistributionNotFound, pkg_resources.VersionConflict): - if not getattr(ssl, 'HAS_SNI', False): - # don't complain on each url processed about the SSL issue - if InsecurePlatformWarning: - requests.packages.urllib3.disable_warnings(InsecurePlatformWarning) - warnings.warn( - 'Some links may return broken results due to being unable to ' - 'check the Server Name Indication (SNI) in the returned SSL cert ' - 'against the hostname in the url requested. Recommended to ' - 'install "requests[security]" as a dependency or upgrade to ' - 'a python version with SNI support (Python 3 and Python 2.7.9+).' - ) - except pkg_resources.UnknownExtra: - warnings.warn( - 'Some links may return broken results due to being unable to ' - 'check the Server Name Indication (SNI) in the returned SSL cert ' - 'against the hostname in the url requested. Recommended to ' - 'install requests-2.4.1+.' - ) + pass # ignored if False: # For type annotation @@ -108,7 +87,7 @@ def ignore_insecure_warning(**kwargs): def _get_tls_cacert(url, config): - # type: (unicode, Config) -> Union[str, bool] + # type: (str, Config) -> Union[str, bool] """Get additional CA cert for a specific URL. This also returns ``False`` if verification is disabled. @@ -120,7 +99,7 @@ def _get_tls_cacert(url, config): certs = getattr(config, 'tls_cacerts', None) if not certs: return True - elif isinstance(certs, (string_types, tuple)): + elif isinstance(certs, (str, tuple)): return certs # type: ignore else: hostname = urlsplit(url)[1] @@ -131,7 +110,7 @@ def _get_tls_cacert(url, config): def get(url, **kwargs): - # type: (unicode, Any) -> requests.Response + # type: (str, Any) -> requests.Response """Sends a GET request like requests.get(). This sets up User-Agent header and TLS verification automatically.""" @@ -145,7 +124,7 @@ def get(url, **kwargs): def head(url, **kwargs): - # type: (unicode, Any) -> requests.Response + # type: (str, Any) -> requests.Response """Sends a HEAD request like requests.head(). This sets up User-Agent header and TLS verification automatically.""" |