From 69bec6730ec9d724bcedeab199d9d684d61423ba Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sun, 21 May 2023 09:56:23 +1200 Subject: [cleanup, utils] Split into submodules (#7090) Closes https://github.com/yt-dlp/yt-dlp/pull/2173 Authored by: pukkandan, coletdjnz Co-authored-by: pukkandan --- yt_dlp/utils/_deprecated.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 yt_dlp/utils/_deprecated.py (limited to 'yt_dlp/utils/_deprecated.py') diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py new file mode 100644 index 000000000..4454d84a7 --- /dev/null +++ b/yt_dlp/utils/_deprecated.py @@ -0,0 +1,30 @@ +"""Deprecated - New code should avoid these""" + +from ._utils import preferredencoding + + +def encodeFilename(s, for_subprocess=False): + assert isinstance(s, str) + return s + + +def decodeFilename(b, for_subprocess=False): + return b + + +def decodeArgument(b): + return b + + +def decodeOption(optval): + if optval is None: + return optval + if isinstance(optval, bytes): + optval = optval.decode(preferredencoding()) + + assert isinstance(optval, str) + return optval + + +def error_to_compat_str(err): + return str(err) -- cgit v1.2.3 From c365dba8430ee33abda85d31f95128605bf240eb Mon Sep 17 00:00:00 2001 From: pukkandan Date: Sat, 15 Jul 2023 14:30:08 +0530 Subject: [networking] Add module (#2861) No actual changes - code is only moved around --- yt_dlp/utils/_deprecated.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'yt_dlp/utils/_deprecated.py') diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py index 4454d84a7..ca0fb1614 100644 --- a/yt_dlp/utils/_deprecated.py +++ b/yt_dlp/utils/_deprecated.py @@ -1,7 +1,26 @@ """Deprecated - New code should avoid these""" +import warnings + +from ..compat.compat_utils import passthrough_module + +# XXX: Implement this the same way as other DeprecationWarnings without circular import +passthrough_module(__name__, '.._legacy', callback=lambda attr: warnings.warn( + DeprecationWarning(f'{__name__}.{attr} is deprecated'), stacklevel=6)) +del passthrough_module + from ._utils import preferredencoding +# isort: split +from ..networking._urllib import PUTRequest # noqa: F401 +from ..networking._urllib import SUPPORTED_ENCODINGS, HEADRequest # noqa: F401 +from ..networking._urllib import HTTPHandler as YoutubeDLHandler # noqa: F401 +from ..networking._urllib import ProxyHandler as PerRequestProxyHandler # noqa: F401 +from ..networking._urllib import RedirectHandler as YoutubeDLRedirectHandler # noqa: F401 +from ..networking._urllib import make_socks_conn_class, update_Request # noqa: F401 +from ..networking.exceptions import network_exceptions # noqa: F401 +from .networking import random_user_agent, std_headers # noqa: F401 + def encodeFilename(s, for_subprocess=False): assert isinstance(s, str) -- cgit v1.2.3 From 227bf1a33be7b89cd7d44ad046844c4ccba104f4 Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 15 Jul 2023 15:55:23 +0530 Subject: [networking] Rewrite architecture (#2861) New networking interface consists of a `RequestDirector` that directs each `Request` to appropriate `RequestHandler` and returns the `Response` or raises `RequestError`. The handlers define adapters to transform its internal Request/Response/Errors to our interfaces. User-facing changes: - Fix issues with per request proxies on redirects for urllib - Support for `ALL_PROXY` environment variable for proxy setting - Support for `socks5h` proxy - Closes https://github.com/yt-dlp/yt-dlp/issues/6325, https://github.com/ytdl-org/youtube-dl/issues/22618, https://github.com/ytdl-org/youtube-dl/pull/28093 - Raise error when using `https` proxy instead of silently converting it to `http` Authored by: coletdjnz --- yt_dlp/utils/_deprecated.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'yt_dlp/utils/_deprecated.py') diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py index ca0fb1614..e55d42354 100644 --- a/yt_dlp/utils/_deprecated.py +++ b/yt_dlp/utils/_deprecated.py @@ -10,16 +10,16 @@ del passthrough_module from ._utils import preferredencoding +from ..networking._urllib import HTTPHandler # isort: split +from .networking import random_user_agent, std_headers # noqa: F401 from ..networking._urllib import PUTRequest # noqa: F401 from ..networking._urllib import SUPPORTED_ENCODINGS, HEADRequest # noqa: F401 -from ..networking._urllib import HTTPHandler as YoutubeDLHandler # noqa: F401 from ..networking._urllib import ProxyHandler as PerRequestProxyHandler # noqa: F401 from ..networking._urllib import RedirectHandler as YoutubeDLRedirectHandler # noqa: F401 from ..networking._urllib import make_socks_conn_class, update_Request # noqa: F401 from ..networking.exceptions import network_exceptions # noqa: F401 -from .networking import random_user_agent, std_headers # noqa: F401 def encodeFilename(s, for_subprocess=False): @@ -47,3 +47,12 @@ def decodeOption(optval): def error_to_compat_str(err): return str(err) + + +class YoutubeDLHandler(HTTPHandler): + def __init__(self, params, *args, **kwargs): + self._params = params + super().__init__(*args, **kwargs) + + +YoutubeDLHTTPSHandler = YoutubeDLHandler -- cgit v1.2.3 From 3d2623a898196640f7cc0fc8b70118ff19e6925d Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sun, 9 Jul 2023 13:23:02 +0530 Subject: [compat, networking] Deprecate old functions (#2861) Authored by: coletdjnz, pukkandan --- yt_dlp/utils/_deprecated.py | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'yt_dlp/utils/_deprecated.py') diff --git a/yt_dlp/utils/_deprecated.py b/yt_dlp/utils/_deprecated.py index e55d42354..a8ae8ecb5 100644 --- a/yt_dlp/utils/_deprecated.py +++ b/yt_dlp/utils/_deprecated.py @@ -10,16 +10,6 @@ del passthrough_module from ._utils import preferredencoding -from ..networking._urllib import HTTPHandler - -# isort: split -from .networking import random_user_agent, std_headers # noqa: F401 -from ..networking._urllib import PUTRequest # noqa: F401 -from ..networking._urllib import SUPPORTED_ENCODINGS, HEADRequest # noqa: F401 -from ..networking._urllib import ProxyHandler as PerRequestProxyHandler # noqa: F401 -from ..networking._urllib import RedirectHandler as YoutubeDLRedirectHandler # noqa: F401 -from ..networking._urllib import make_socks_conn_class, update_Request # noqa: F401 -from ..networking.exceptions import network_exceptions # noqa: F401 def encodeFilename(s, for_subprocess=False): @@ -47,12 +37,3 @@ def decodeOption(optval): def error_to_compat_str(err): return str(err) - - -class YoutubeDLHandler(HTTPHandler): - def __init__(self, params, *args, **kwargs): - self._params = params - super().__init__(*args, **kwargs) - - -YoutubeDLHTTPSHandler = YoutubeDLHandler -- cgit v1.2.3