Skip to content

Commit 36ce5f3

Browse files
authored
Remove old aliases to OSError (#1473)
1 parent 2573f8e commit 36ce5f3

File tree

8 files changed

+10
-15
lines changed

8 files changed

+10
-15
lines changed

pymodbus/client/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def _get_address_family(cls, address):
335335
"""Get the correct address family."""
336336
try:
337337
_ = socket.inet_pton(socket.AF_INET6, address)
338-
except socket.error: # not a valid ipv6 address
338+
except OSError: # not a valid ipv6 address
339339
return socket.AF_INET
340340
return socket.AF_INET6
341341

pymodbus/client/sync_diag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def connect(self):
101101
timeout=self.params.timeout,
102102
source_address=self.params.source_address,
103103
)
104-
except socket.error as msg:
104+
except OSError as msg:
105105
Log.error(LOG_MSGS["connfail_msg"], self.params.host, self.params.port, msg)
106106
self.close()
107107
return self.socket is not None

pymodbus/client/tcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def connect(self):
218218
"Connection to Modbus server established. Socket {}",
219219
self.socket.getsockname(),
220220
)
221-
except socket.error as msg:
221+
except OSError as msg:
222222
Log.error(
223223
"Connection to ({}, {}) failed: {}",
224224
self.params.host,

pymodbus/client/tls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def connect(self):
176176
)
177177
self.socket.settimeout(self.params.timeout)
178178
self.socket.connect((self.params.host, self.params.port))
179-
except socket.error as msg:
179+
except OSError as msg:
180180
Log.error(
181181
"Connection to ({}, {}) failed: {}",
182182
self.params.host,

pymodbus/client/udp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def connect(self):
213213
family = ModbusUdpClient._get_address_family(self.params.host)
214214
self.socket = socket.socket(family, socket.SOCK_DGRAM)
215215
self.socket.settimeout(self.params.timeout)
216-
except socket.error as exc:
216+
except OSError as exc:
217217
Log.error("Unable to create udp socket {}", exc)
218218
self.close()
219219
return self.socket is not None

pymodbus/transaction.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
]
1212

1313
# pylint: disable=missing-type-doc
14-
import socket
1514
import struct
1615
import time
1716
from functools import partial
@@ -317,11 +316,7 @@ def _transact(self, packet, response_length, full=False, broadcast=False):
317316
result = self._recv(response_length, full)
318317
# result2 = self._recv(response_length, full)
319318
Log.debug("RECV: {}", result, ":hex")
320-
except (
321-
socket.error,
322-
ModbusIOException,
323-
InvalidMessageReceivedException,
324-
) as msg:
319+
except (OSError, ModbusIOException, InvalidMessageReceivedException) as msg:
325320
if self.reset_socket:
326321
self.client.close()
327322
Log.debug("Transaction failed. ({}) ", msg)

test/test_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def settimeout(self, *a, **kwa):
489489
assert client.connect()
490490

491491
with mock.patch.object(socket, "socket") as mock_method:
492-
mock_method.side_effect = socket.error()
492+
mock_method.side_effect = OSError()
493493
client = lib_client.ModbusUdpClient("127.0.0.1")
494494
assert not client.connect()
495495

@@ -504,7 +504,7 @@ def test_client_tcp_connect():
504504
assert client.connect()
505505

506506
with mock.patch.object(socket, "create_connection") as mock_method:
507-
mock_method.side_effect = socket.error()
507+
mock_method.side_effect = OSError()
508508
client = lib_client.ModbusTcpClient("127.0.0.1")
509509
assert not client.connect()
510510

@@ -516,7 +516,7 @@ def test_client_tls_connect():
516516
assert client.connect()
517517

518518
with mock.patch.object(socket, "create_connection") as mock_method:
519-
mock_method.side_effect = socket.error()
519+
mock_method.side_effect = OSError()
520520
client = lib_client.ModbusTlsClient("127.0.0.1")
521521
assert not client.connect()
522522

test/test_client_sync_diag.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_tcp_diag_client_connect(self):
4848
assert client.connect()
4949

5050
with mock.patch.object(socket, "create_connection") as mock_method:
51-
mock_method.side_effect = socket.error()
51+
mock_method.side_effect = OSError()
5252
client = ModbusTcpDiagClient()
5353
assert not client.connect()
5454

0 commit comments

Comments
 (0)