Turn socket.timeout error into the more general TimeoutError

This commit is contained in:
Lonami Exo 2017-09-03 10:01:00 +02:00
parent 494b82ea9d
commit 2a5d08b23d

View File

@ -69,6 +69,8 @@ class TcpClient:
# The socket timeout is now the maximum total duration to send all data. # The socket timeout is now the maximum total duration to send all data.
try: try:
self._socket.sendall(data) self._socket.sendall(data)
except socket.timeout as e:
raise TimeoutError() from e
except BrokenPipeError: except BrokenPipeError:
self.close() self.close()
raise raise
@ -86,7 +88,11 @@ class TcpClient:
with BufferedWriter(BytesIO(), buffer_size=size) as buffer: with BufferedWriter(BytesIO(), buffer_size=size) as buffer:
bytes_left = size bytes_left = size
while bytes_left != 0: 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: if len(partial) == 0:
self.close() self.close()
raise ConnectionResetError( raise ConnectionResetError(