From 2a5d08b23df37478dc6546855447d2960aa90f55 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 3 Sep 2017 10:01:00 +0200 Subject: [PATCH] Turn socket.timeout error into the more general TimeoutError --- telethon/extensions/tcp_client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/telethon/extensions/tcp_client.py b/telethon/extensions/tcp_client.py index bd969084..de3bdcf1 100644 --- a/telethon/extensions/tcp_client.py +++ b/telethon/extensions/tcp_client.py @@ -69,6 +69,8 @@ class TcpClient: # The socket timeout is now the maximum total duration to send all data. try: self._socket.sendall(data) + except socket.timeout as e: + raise TimeoutError() from e except BrokenPipeError: self.close() raise @@ -86,7 +88,11 @@ class TcpClient: with BufferedWriter(BytesIO(), buffer_size=size) as buffer: bytes_left = size while bytes_left != 0: - partial = self._socket.recv(bytes_left) + try: + partial = self._socket.recv(bytes_left) + except socket.timeout as e: + raise TimeoutError() from e + if len(partial) == 0: self.close() raise ConnectionResetError(