diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2024-05-08 11:10:05 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2024-05-08 11:21:05 +0300 |
commit | 4196c19bc0753c1c2fe4d29f231bb49039430f9f (patch) | |
tree | f02ac799e7260353047c65d46fa5ce206f2e9303 /contrib/python/websocket-client/py3/websocket/_app.py | |
parent | c3d51e170ca39637234e72ae19dcbc53b737a83e (diff) | |
download | ydb-4196c19bc0753c1c2fe4d29f231bb49039430f9f.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/python/websocket-client/py3/websocket/_app.py')
-rw-r--r-- | contrib/python/websocket-client/py3/websocket/_app.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/contrib/python/websocket-client/py3/websocket/_app.py b/contrib/python/websocket-client/py3/websocket/_app.py index 4d8af3b5b1..9fee76546b 100644 --- a/contrib/python/websocket-client/py3/websocket/_app.py +++ b/contrib/python/websocket-client/py3/websocket/_app.py @@ -13,13 +13,14 @@ from ._exceptions import ( WebSocketException, WebSocketTimeoutException, ) +from ._ssl_compat import SSLEOFError from ._url import parse_url """ _app.py websocket - WebSocket client library for Python -Copyright 2023 engn33r +Copyright 2024 engn33r Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -165,6 +166,7 @@ class WebSocketApp: url: str, header: Union[list, dict, Callable, None] = None, on_open: Optional[Callable[[WebSocket], None]] = None, + on_reconnect: Optional[Callable[[WebSocket], None]] = None, on_message: Optional[Callable[[WebSocket, Any], None]] = None, on_error: Optional[Callable[[WebSocket, Any], None]] = None, on_close: Optional[Callable[[WebSocket, Any, Any], None]] = None, @@ -194,6 +196,10 @@ class WebSocketApp: Callback object which is called at opening websocket. on_open has one argument. The 1st argument is this class object. + on_reconnect: function + Callback object which is called at reconnecting websocket. + on_reconnect has one argument. + The 1st argument is this class object. on_message: function Callback object which is called when received data. on_message has 2 arguments. @@ -244,6 +250,7 @@ class WebSocketApp: self.cookie = cookie self.on_open = on_open + self.on_reconnect = on_reconnect self.on_message = on_message self.on_data = on_data self.on_error = on_error @@ -424,6 +431,7 @@ class WebSocketApp: self.ping_interval = ping_interval self.ping_timeout = ping_timeout self.ping_payload = ping_payload + self.has_done_teardown = False self.keep_running = True def teardown(close_frame: ABNF = None): @@ -495,7 +503,10 @@ class WebSocketApp: if self.ping_interval: self._start_ping_thread() - self._callback(self.on_open) + if reconnecting and self.on_reconnect: + self._callback(self.on_reconnect) + else: + self._callback(self.on_open) dispatcher.read(self.sock.sock, read, check) except ( @@ -516,9 +527,10 @@ class WebSocketApp: except ( WebSocketConnectionClosedException, KeyboardInterrupt, + SSLEOFError, ) as e: if custom_dispatcher: - return handleDisconnect(e) + return handleDisconnect(e, bool(reconnect)) else: raise e |