diff options
author | AlexSm <alex@ydb.tech> | 2023-12-21 15:05:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-21 15:05:38 +0100 |
commit | e98bcbc74422492351c51646dba3849a138a8ffc (patch) | |
tree | 38ad7a09b1f9c201ce8a7e3d69f2017388769224 /contrib/python/websocket-client/py3/websocket/_socket.py | |
parent | 559d7083cd8378cb25b9e966dedcca21d413e338 (diff) | |
download | ydb-e98bcbc74422492351c51646dba3849a138a8ffc.tar.gz |
Import libs 1 (#590)
* Import libs 1
* Add new file without extension
* Add file missed in export config
Diffstat (limited to 'contrib/python/websocket-client/py3/websocket/_socket.py')
-rw-r--r-- | contrib/python/websocket-client/py3/websocket/_socket.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/contrib/python/websocket-client/py3/websocket/_socket.py b/contrib/python/websocket-client/py3/websocket/_socket.py index 1575a0c0c3..f0ad27a5d4 100644 --- a/contrib/python/websocket-client/py3/websocket/_socket.py +++ b/contrib/python/websocket-client/py3/websocket/_socket.py @@ -1,7 +1,6 @@ import errno import selectors import socket - from typing import Union from ._exceptions import * @@ -39,12 +38,18 @@ if hasattr(socket, "TCP_KEEPCNT"): _default_timeout = None -__all__ = ["DEFAULT_SOCKET_OPTION", "sock_opt", "setdefaulttimeout", "getdefaulttimeout", - "recv", "recv_line", "send"] +__all__ = [ + "DEFAULT_SOCKET_OPTION", + "sock_opt", + "setdefaulttimeout", + "getdefaulttimeout", + "recv", + "recv_line", + "send", +] class sock_opt: - def __init__(self, sockopt: list, sslopt: dict) -> None: if sockopt is None: sockopt = [] @@ -91,7 +96,7 @@ def recv(sock: socket.socket, bufsize: int) -> bytes: pass except socket.error as exc: error_code = extract_error_code(exc) - if error_code != errno.EAGAIN and error_code != errno.EWOULDBLOCK: + if error_code not in [errno.EAGAIN, errno.EWOULDBLOCK]: raise sel = selectors.DefaultSelector() @@ -115,14 +120,13 @@ def recv(sock: socket.socket, bufsize: int) -> bytes: raise WebSocketTimeoutException(message) except SSLError as e: message = extract_err_message(e) - if isinstance(message, str) and 'timed out' in message: + if isinstance(message, str) and "timed out" in message: raise WebSocketTimeoutException(message) else: raise if not bytes_: - raise WebSocketConnectionClosedException( - "Connection to remote host was lost.") + raise WebSocketConnectionClosedException("Connection to remote host was lost.") return bytes_ @@ -132,14 +136,14 @@ def recv_line(sock: socket.socket) -> bytes: while True: c = recv(sock, 1) line.append(c) - if c == b'\n': + if c == b"\n": break - return b''.join(line) + return b"".join(line) def send(sock: socket.socket, data: Union[bytes, str]) -> int: if isinstance(data, str): - data = data.encode('utf-8') + data = data.encode("utf-8") if not sock: raise WebSocketConnectionClosedException("socket is already closed.") @@ -153,7 +157,7 @@ def send(sock: socket.socket, data: Union[bytes, str]) -> int: error_code = extract_error_code(exc) if error_code is None: raise - if error_code != errno.EAGAIN and error_code != errno.EWOULDBLOCK: + if error_code not in [errno.EAGAIN, errno.EWOULDBLOCK]: raise sel = selectors.DefaultSelector() |