diff options
author | Jesus <heckyel@riseup.net> | 2023-09-04 01:37:13 +0800 |
---|---|---|
committer | Jesus <heckyel@riseup.net> | 2023-09-04 01:37:13 +0800 |
commit | 52d97967fb3b196759c19ae40a4c63dbb2557a19 (patch) | |
tree | c49e561914d2d01f2ef022443d304728a08dac25 /yt_dlp/compat/urllib | |
parent | a9d0affcff8d499212852d9c711112b29defe612 (diff) | |
parent | 2301b5c1b77a65abbb46b72f91e1e4666fd5d985 (diff) | |
download | hypervideo-pre-52d97967fb3b196759c19ae40a4c63dbb2557a19.tar.lz hypervideo-pre-52d97967fb3b196759c19ae40a4c63dbb2557a19.tar.xz hypervideo-pre-52d97967fb3b196759c19ae40a4c63dbb2557a19.zip |
update from upstream
Diffstat (limited to 'yt_dlp/compat/urllib')
-rw-r--r-- | yt_dlp/compat/urllib/__init__.py | 10 | ||||
-rw-r--r-- | yt_dlp/compat/urllib/request.py | 40 |
2 files changed, 50 insertions, 0 deletions
diff --git a/yt_dlp/compat/urllib/__init__.py b/yt_dlp/compat/urllib/__init__.py new file mode 100644 index 000000000..b27cc6133 --- /dev/null +++ b/yt_dlp/compat/urllib/__init__.py @@ -0,0 +1,10 @@ +# flake8: noqa: F405 +from urllib import * # noqa: F403 + +del request +from . import request # noqa: F401 + +from ..compat_utils import passthrough_module + +passthrough_module(__name__, 'urllib') +del passthrough_module diff --git a/yt_dlp/compat/urllib/request.py b/yt_dlp/compat/urllib/request.py new file mode 100644 index 000000000..ff63b2f0e --- /dev/null +++ b/yt_dlp/compat/urllib/request.py @@ -0,0 +1,40 @@ +# flake8: noqa: F405 +from urllib.request import * # noqa: F403 + +from ..compat_utils import passthrough_module + +passthrough_module(__name__, 'urllib.request') +del passthrough_module + + +from .. import compat_os_name + +if compat_os_name == 'nt': + # On older python versions, proxies are extracted from Windows registry erroneously. [1] + # If the https proxy in the registry does not have a scheme, urllib will incorrectly add https:// to it. [2] + # It is unlikely that the user has actually set it to be https, so we should be fine to safely downgrade + # it to http on these older python versions to avoid issues + # This also applies for ftp proxy type, as ftp:// proxy scheme is not supported. + # 1: https://github.com/python/cpython/issues/86793 + # 2: https://github.com/python/cpython/blob/51f1ae5ceb0673316c4e4b0175384e892e33cc6e/Lib/urllib/request.py#L2683-L2698 + import sys + from urllib.request import getproxies_environment, getproxies_registry + + def getproxies_registry_patched(): + proxies = getproxies_registry() + if ( + sys.version_info >= (3, 10, 5) # https://docs.python.org/3.10/whatsnew/changelog.html#python-3-10-5-final + or (3, 9, 13) <= sys.version_info < (3, 10) # https://docs.python.org/3.9/whatsnew/changelog.html#python-3-9-13-final + ): + return proxies + + for scheme in ('https', 'ftp'): + if scheme in proxies and proxies[scheme].startswith(f'{scheme}://'): + proxies[scheme] = 'http' + proxies[scheme][len(scheme):] + + return proxies + + def getproxies(): + return getproxies_environment() or getproxies_registry_patched() + +del compat_os_name |