Use legacy websockets API

websockets 14 uses the legacy API by default. Explictly use the legacy
API so that yt-dlp works with websockets 14+.

websockets supports the legacy API until 2030.

Ref: https://websockets.readthedocs.io/en/stable/howto/upgrade.html
Ref: https://websockets.readthedocs.io/en/stable/project/changelog.html#backwards-incompatible-changes
This commit is contained in:
fossdd 2024-11-22 23:08:59 +01:00
parent f919729538
commit 71299aaddb
No known key found for this signature in database
GPG Key ID: BB8C8A81C6452A88
4 changed files with 6 additions and 6 deletions

View File

@ -52,7 +52,7 @@ default = [
"pycryptodomex",
"requests>=2.32.2,<3",
"urllib3>=1.26.17,<3",
"websockets>=13.0,<14",
"websockets>=13.0",
]
curl-cffi = [
"curl-cffi==0.5.10; os_name=='nt' and implementation_name=='cpython'",

View File

@ -212,9 +212,9 @@ def do_GET(self):
class SocksWebSocketTestRequestHandler(SocksTestRequestHandler):
def handle(self):
import websockets.sync.server
import websockets.legacy.sync.server
protocol = websockets.ServerProtocol()
connection = websockets.sync.server.ServerConnection(socket=self.request, protocol=protocol, close_timeout=0)
connection = websockets.legacy.sync.server.ServerConnection(socket=self.request, protocol=protocol, close_timeout=0)
connection.handshake()
connection.send(json.dumps(self.socks_info))
connection.close()

View File

@ -52,7 +52,7 @@
try:
import websockets
import websockets.legacy as websockets
except ImportError:
websockets = None

View File

@ -36,7 +36,7 @@
if websockets_version < (13, 0):
raise ImportError('Only websockets>=13.0 is supported')
import websockets.sync.client
import websockets.legacy.sync.client
from websockets.uri import parse_uri
# In websockets Connection, recv_exc and recv_events_exc are defined
@ -45,7 +45,7 @@
# where the recv events handler thread tries to use these attributes before they are defined [2].
# 1: https://github.com/python-websockets/websockets/blame/de768cf65e7e2b1a3b67854fb9e08816a5ff7050/src/websockets/sync/connection.py#L93
# 2: "AttributeError: 'ClientConnection' object has no attribute 'recv_events_exc'. Did you mean: 'recv_events'?"
import websockets.sync.connection # isort: split
import websockets.legacy.sync.connection # isort: split
with contextlib.suppress(Exception):
websockets.sync.connection.Connection.recv_exc = None