Skip to content

Commit

Permalink
partially revert a9674a0
Browse files Browse the repository at this point in the history
  • Loading branch information
pukkandan committed Jul 22, 2023
1 parent 7865a5b commit f8e5ce7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions test/test_networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,8 @@ def __init__(self, request):

class FakeRH(RequestHandler):

def validate(self, request):
assert isinstance(request, Request)
def _validate(self, request):
return

def _send(self, request: Request):
if request.url.startswith('ssl://'):
Expand Down
18 changes: 10 additions & 8 deletions yt_dlp/networking/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
TransportError,
UnsupportedRequest,
)
from ..compat import types
from ..utils import (
bug_reports_message,
classproperty,
Expand Down Expand Up @@ -140,7 +139,7 @@ class RequestHandler(abc.ABC):
If a Request is not supported by the handler, an UnsupportedRequest
should be raised with a reason.
By default, some checks are done on the request in validate() based on the following class variables:
By default, some checks are done on the request in _validate() based on the following class variables:
- `_SUPPORTED_URL_SCHEMES`: a tuple of supported url schemes.
Any Request with an url scheme not in this list will raise an UnsupportedRequest.
Expand Down Expand Up @@ -272,13 +271,10 @@ def _check_proxies(self, proxies):

def _check_extensions(self, extensions):
"""Check extensions for unsupported extensions. Subclasses should extend this."""
assert isinstance(extensions.get('cookiejar'), (CookieJar, types.NoneType))
assert isinstance(extensions.get('timeout'), (float, int, types.NoneType))
assert isinstance(extensions.get('cookiejar'), (CookieJar, type(None)))
assert isinstance(extensions.get('timeout'), (float, int, type(None)))

@wrap_request_errors
def validate(self, request: Request):
if not isinstance(request, Request):
raise TypeError('Expected an instance of Request')
def _validate(self, request):
self._check_url_scheme(request)
self._check_proxies(request.proxies or self.proxies)
extensions = request.extensions.copy()
Expand All @@ -287,6 +283,12 @@ def validate(self, request: Request):
# TODO: add support for optional extensions
raise UnsupportedRequest(f'Unsupported extensions: {", ".join(extensions.keys())}')

@wrap_request_errors
def validate(self, request: Request):
if not isinstance(request, Request):
raise TypeError('Expected an instance of Request')
self._validate(request)

@wrap_request_errors
def send(self, request: Request) -> Response:
if not isinstance(request, Request):
Expand Down

0 comments on commit f8e5ce7

Please sign in to comment.