From 833862cfbc5e5b978d928d671db3b680cd823d22 Mon Sep 17 00:00:00 2001 From: coletdjnz Date: Sat, 6 Apr 2024 15:50:48 +1300 Subject: [PATCH] misc cleanup --- test/test_http_proxy.py | 11 ++--------- yt_dlp/networking/_websockets.py | 15 ++++++--------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/test/test_http_proxy.py b/test/test_http_proxy.py index 54a176d34a..6e27bc6d50 100644 --- a/test/test_http_proxy.py +++ b/test/test_http_proxy.py @@ -8,7 +8,7 @@ import ssl import threading from http.server import BaseHTTPRequestHandler -from socketserver import ThreadingTCPServer +from socketserver import BaseRequestHandler, ThreadingTCPServer import pytest @@ -224,7 +224,7 @@ def proxy_server(proxy_server_class, request_handler, bind_ip=None, **proxy_serv finally: server.shutdown() server.server_close() - server_thread.join() + server_thread.join(2.0) class HTTPProxyTestContext(abc.ABC): @@ -304,7 +304,6 @@ def test_http_no_auth(self, handler, ctx): assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is False assert 'Proxy-Authorization' not in proxy_info['headers'] - assert proxy_info['proxy'] == server_address def test_http_auth(self, handler, ctx): with ctx.http_server(HTTPProxyHandler, username='test', password='test') as server_address: @@ -339,7 +338,6 @@ def test_https(self, handler, ctx): assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is False assert 'Proxy-Authorization' not in proxy_info['headers'] - assert proxy_info['proxy'] == server_address @pytest.mark.skip_handler('Urllib', 'urllib does not support https proxies') def test_https_verify_failed(self, handler, ctx): @@ -358,7 +356,6 @@ def test_http_with_idn(self, handler, ctx): assert proxy_info['proxy'] == server_address assert proxy_info['path'].startswith('http://xn--fiq228c.tw') assert proxy_info['headers']['Host'].split(':', 1)[0] == 'xn--fiq228c.tw' - assert proxy_info['proxy'] == server_address @pytest.mark.parametrize( @@ -376,7 +373,6 @@ def test_http_connect_no_auth(self, handler, ctx): assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is True assert 'Proxy-Authorization' not in proxy_info['headers'] - assert proxy_info['proxy'] == server_address def test_http_connect_auth(self, handler, ctx): with ctx.http_server(HTTPConnectProxyHandler, username='test', password='test') as server_address: @@ -384,7 +380,6 @@ def test_http_connect_auth(self, handler, ctx): proxy_info = ctx.proxy_info_request(rh) assert proxy_info['proxy'] == server_address assert 'Proxy-Authorization' in proxy_info['headers'] - assert proxy_info['proxy'] == server_address @pytest.mark.skip_handler( 'Requests', @@ -415,7 +410,6 @@ def test_https_connect_proxy(self, handler, ctx): assert proxy_info['proxy'] == server_address assert proxy_info['connect'] is True assert 'Proxy-Authorization' not in proxy_info['headers'] - assert proxy_info['proxy'] == server_address @pytest.mark.skipif(urllib3 is None, reason='requires urllib3 to test') def test_https_connect_verify_failed(self, handler, ctx): @@ -434,4 +428,3 @@ def test_https_connect_proxy_auth(self, handler, ctx): proxy_info = ctx.proxy_info_request(rh) assert proxy_info['proxy'] == server_address assert 'Proxy-Authorization' in proxy_info['headers'] - assert proxy_info['proxy'] == server_address diff --git a/yt_dlp/networking/_websockets.py b/yt_dlp/networking/_websockets.py index b13e892cee..0a3d50ad94 100644 --- a/yt_dlp/networking/_websockets.py +++ b/yt_dlp/networking/_websockets.py @@ -1,10 +1,13 @@ from __future__ import annotations +import base64 import contextlib import io import logging import ssl import sys +import urllib.parse +from http.client import HTTPConnection, HTTPResponse from ._helper import ( create_connection, @@ -19,19 +22,14 @@ ProxyError, RequestError, SSLError, - TransportError, UnsupportedRequest, + TransportError, + UnsupportedRequest, ) from .websocket import WebSocketRequestHandler, WebSocketResponse from ..compat import functools -from ..dependencies import websockets, urllib3 +from ..dependencies import urllib3, websockets from ..socks import ProxyError as SocksProxyError from ..utils import int_or_none -import io -import urllib.parse -import base64 - -from http.client import HTTPResponse, HTTPConnection - from ..utils.networking import HTTPHeaderDict if not websockets: @@ -282,7 +280,6 @@ def create_http_connect_conn( password=None, ): - # todo: handle ipv6 host proxy_headers = HTTPHeaderDict({ **(headers or {}), })