Skip to content

Commit 2432810

Browse files
Deprecated exception alias: IOError → OSError
https://docs.python.org/3/library/exceptions.html#IOError
1 parent b4bb70c commit 2432810

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

bin/create_iods_modules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ def _create_modules(directory):
105105
except IndexError:
106106
raise ValueError('Path to directory must be provided.')
107107
if not os.path.exists(directory):
108-
raise IOError('Path does not exist: "{}"'.format(directory))
108+
raise OSError('Path does not exist: "{}"'.format(directory))
109109
if not os.path.isdir(directory):
110-
raise IOError('Path is not a directory: "{}"'.format(directory))
110+
raise OSError('Path is not a directory: "{}"'.format(directory))
111111

112112
now = datetime.datetime.now()
113113
current_date = datetime.datetime.date(now).strftime('%Y-%m-%d')

src/highdicom/io.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ def _read_bot(fp: DicomFileLike) -> List[int]:
106106
107107
Raises
108108
------
109-
IOError
109+
OSError
110110
When file pointer is not positioned at first byte of Pixel Data element
111111
112112
"""
113113
tag = TupleTag(fp.read_tag())
114114
if int(tag) not in _PIXEL_DATA_TAGS:
115-
raise IOError(
115+
raise OSError(
116116
'Expected file pointer at first byte of Pixel Data element.'
117117
)
118118
# Skip Pixel Data element header (tag, VR, length)
@@ -148,7 +148,7 @@ def _build_bot(fp: DicomFileLike, number_of_frames: int) -> List[int]:
148148
149149
Raises
150150
------
151-
IOError
151+
OSError
152152
When file pointer is not positioned at first byte of first Frame item
153153
after Basic Offset Table item or when parsing of Frame item headers
154154
fails
@@ -167,20 +167,20 @@ def _build_bot(fp: DicomFileLike, number_of_frames: int) -> List[int]:
167167
break
168168
if int(tag) != ItemTag:
169169
fp.seek(initial_position, 0)
170-
raise IOError(
170+
raise OSError(
171171
'Building Basic Offset Table (BOT) failed. '
172172
f'Expected tag of Frame item #{i} at position {frame_position}.'
173173
)
174174
length = fp.read_UL()
175175
if length % 2:
176176
fp.seek(initial_position, 0)
177-
raise IOError(
177+
raise OSError(
178178
'Building Basic Offset Table (BOT) failed. '
179179
f'Length of Frame item #{i} is not a multiple of 2.'
180180
)
181181
elif length == 0:
182182
fp.seek(initial_position, 0)
183-
raise IOError(
183+
raise OSError(
184184
'Building Basic Offset Table (BOT) failed. '
185185
f'Length of Frame item #{i} is zero.'
186186
)
@@ -299,7 +299,7 @@ def open(self) -> None:
299299
When file cannot be found
300300
OSError
301301
When file cannot be opened
302-
IOError
302+
OSError
303303
When DICOM metadata cannot be read from file
304304
ValueError
305305
When DICOM dataset contained in file does not represent an image
@@ -373,12 +373,12 @@ def _read_metadata(self) -> None:
373373
"""
374374
logger.debug('read metadata elements')
375375
if self._fp is None:
376-
raise IOError('File has not been opened for reading.')
376+
raise OSError('File has not been opened for reading.')
377377

378378
try:
379379
metadata = dcmread(self._fp, stop_before_pixels=True)
380380
except Exception as err:
381-
raise IOError(f'DICOM metadata cannot be read from file: "{err}"')
381+
raise OSError(f'DICOM metadata cannot be read from file: "{err}"')
382382

383383
# Cache Transfer Syntax UID, since we need it to decode frame items
384384
self._transfer_syntax_uid = UID(metadata.file_meta.TransferSyntaxUID)
@@ -413,7 +413,7 @@ def _read_metadata(self) -> None:
413413
try:
414414
self._basic_offset_table = _get_bot(self._fp, number_of_frames)
415415
except Exception as err:
416-
raise IOError(f'Failed to build Basic Offset Table: "{err}"')
416+
raise OSError(f'Failed to build Basic Offset Table: "{err}"')
417417
self._first_frame_offset = self._fp.tell()
418418
else:
419419
if self._fp.is_implicit_VR:
@@ -516,7 +516,7 @@ def read_frame_raw(self, index: int) -> bytes:
516516
517517
Raises
518518
------
519-
IOError
519+
OSError
520520
When frame could not be read
521521
522522
"""
@@ -549,7 +549,7 @@ def read_frame_raw(self, index: int) -> bytes:
549549
frame_data = self._fp.read(self._bytes_per_frame_uncompressed)
550550

551551
if len(frame_data) == 0:
552-
raise IOError(f'Failed to read frame #{index}.')
552+
raise OSError(f'Failed to read frame #{index}.')
553553

554554
return frame_data
555555

@@ -574,7 +574,7 @@ def read_frame(self, index: int, correct_color: bool = True) -> np.ndarray:
574574
575575
Raises
576576
------
577-
IOError
577+
OSError
578578
When frame could not be read
579579
580580
"""

0 commit comments

Comments
 (0)