Skip to content

Commit

Permalink
Replace deprecated aliases of exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed Oct 8, 2023
1 parent 2aa9ed7 commit a736278
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions pynetdicom/apps/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def handle_store(event, args, app_logger):
app_logger.error("Unable to create the output directory:")
app_logger.error(f" {args.output_directory}")
app_logger.exception(exc)
# Failed - Out of Resources - IOError
# Failed - Out of Resources - OSError
status_ds.Status = 0xA700
return status_ds

Expand All @@ -639,11 +639,11 @@ def handle_store(event, args, app_logger):
ds.save_as(filename, write_like_original=False)

status_ds.Status = 0x0000 # Success
except IOError as exc:
except OSError as exc:
app_logger.error("Could not write file to specified directory:")
app_logger.error(f" {os.path.dirname(filename)}")
app_logger.exception(exc)
# Failed - Out of Resources - IOError
# Failed - Out of Resources - OSError
status_ds.Status = 0xA700
except Exception as exc:
app_logger.error("Could not write file to specified directory:")
Expand Down
4 changes: 2 additions & 2 deletions pynetdicom/dul.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def _read_pdu_data(self) -> None:
# Try and read the PDU type and length from the socket
try:
bytestream.extend(self.socket.recv(6))
except (socket.error, socket.timeout) as exc:
except (OSError, TimeoutError) as exc:
# READ_PDU_EXC_A
LOGGER.error("Connection closed before the entire PDU was received")
LOGGER.exception(exc)
Expand Down Expand Up @@ -298,7 +298,7 @@ def _read_pdu_data(self) -> None:
# Try and read the rest of the PDU
try:
bytestream += self.socket.recv(pdu_length)
except (socket.error, socket.timeout) as exc:
except (OSError, TimeoutError) as exc:
# READ_PDU_EXC_D
LOGGER.error("Connection closed before the entire PDU was received")
LOGGER.exception(exc)
Expand Down
8 changes: 4 additions & 4 deletions pynetdicom/tests/parrot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def ready(self):
try:
# Use a timeout of 0 so we get an "instant" result
ready, _, _ = select.select([self.socket], [], [], 0.5)
except (socket.error, socket.timeout, ValueError):
except (OSError, TimeoutError, ValueError):
return False

return bool(ready)
Expand All @@ -73,7 +73,7 @@ def read_data(self):
# Try and read the PDU type and length from the socket
try:
bytestream.extend(self.recv(6))
except (socket.error, socket.timeout):
except (OSError, TimeoutError):
pass
try:
# Byte 1 is always the PDU type
Expand All @@ -86,7 +86,7 @@ def read_data(self):
# Try and read the rest of the PDU
try:
bytestream += self.recv(pdu_length)
except (socket.error, socket.timeout):
except (OSError, TimeoutError):
pass

return bytestream
Expand Down Expand Up @@ -154,7 +154,7 @@ def send(self, bytestream):
# Returns the number of bytes sent
nr_sent = self.socket.send(bytestream)
total_sent += nr_sent
except (socket.error, socket.timeout):
except (OSError, TimeoutError):
# Evt17: Transport connection closed
return False

Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_fsm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1846,7 +1846,7 @@ def connect(primitive):
try:
assoc.dul.socket.socket.connect(address)
assoc.dul.socket._is_connected = True
except (socket.error, socket.timeout) as exc:
except (OSError, TimeoutError) as exc:
assoc.dul.socket.close()

assoc.dul.socket.connect = connect
Expand Down
2 changes: 1 addition & 1 deletion pynetdicom/tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ class DummyAE:
server.shutdown()

if sys.version_info[0] == 2:
with pytest.raises(socket.error):
with pytest.raises(OSError):
server.socket.fileno()
else:
assert server.socket.fileno() == -1
Expand Down
10 changes: 5 additions & 5 deletions pynetdicom/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def close(self) -> None:

try:
self.socket.shutdown(socket.SHUT_RDWR)
except socket.error:
except OSError:
pass

self.socket.close()
Expand Down Expand Up @@ -238,7 +238,7 @@ def connect(self, primitive: T_CONNECT) -> None:
# Set ae connection timeout
self.socket.settimeout(self.assoc.connection_timeout)
# Try and connect to remote at (address, port)
# raises socket.error if connection refused
# raises OSError if connection refused
self.socket.connect(primitive.address)
# Clear ae connection timeout
self.socket.settimeout(None)
Expand Down Expand Up @@ -363,7 +363,7 @@ def ready(self) -> bool:
try:
# Use a timeout of 0 so we get an "instant" result
ready, _, _ = select.select([self.socket], [], [], 0)
except (socket.error, socket.timeout, ValueError):
except (OSError, TimeoutError, ValueError):
# Evt17: Transport connection closed
self.event_queue.put("Evt17")
return False
Expand Down Expand Up @@ -442,7 +442,7 @@ def send(self, bytestream: bytes) -> None:
total_sent += nr_sent

evt.trigger(self.assoc, evt.EVT_DATA_SENT, {"data": bytestream})
except (socket.error, socket.timeout):
except (OSError, TimeoutError):
# Evt17: Transport connection closed
self.event_queue.put("Evt17")

Expand Down Expand Up @@ -816,7 +816,7 @@ def server_close(self) -> None:
self.socket = cast(socket.socket, self.socket)
try:
self.socket.shutdown(socket.SHUT_RDWR)
except socket.error:
except OSError:
pass

self.socket.close()
Expand Down

0 comments on commit a736278

Please sign in to comment.