Skip to content

Commit

Permalink
Merge pull request #257 from DimitriPapadopoulos/IOError
Browse files Browse the repository at this point in the history
Deprecated exception alias: `IOError` → `OSError`
  • Loading branch information
CPBridge committed Oct 11, 2023
2 parents d8e4358 + 2432810 commit bc565c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions bin/create_iods_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def _create_modules(directory):
except IndexError:
raise ValueError('Path to directory must be provided.')
if not os.path.exists(directory):
raise IOError('Path does not exist: "{}"'.format(directory))
raise OSError('Path does not exist: "{}"'.format(directory))
if not os.path.isdir(directory):
raise IOError('Path is not a directory: "{}"'.format(directory))
raise OSError('Path is not a directory: "{}"'.format(directory))

now = datetime.datetime.now()
current_date = datetime.datetime.date(now).strftime('%Y-%m-%d')
Expand Down
26 changes: 13 additions & 13 deletions src/highdicom/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ def _read_bot(fp: DicomFileLike) -> List[int]:
Raises
------
IOError
OSError
When file pointer is not positioned at first byte of Pixel Data element
"""
tag = TupleTag(fp.read_tag())
if int(tag) not in _PIXEL_DATA_TAGS:
raise IOError(
raise OSError(
'Expected file pointer at first byte of Pixel Data element.'
)
# Skip Pixel Data element header (tag, VR, length)
Expand Down Expand Up @@ -148,7 +148,7 @@ def _build_bot(fp: DicomFileLike, number_of_frames: int) -> List[int]:
Raises
------
IOError
OSError
When file pointer is not positioned at first byte of first Frame item
after Basic Offset Table item or when parsing of Frame item headers
fails
Expand All @@ -167,20 +167,20 @@ def _build_bot(fp: DicomFileLike, number_of_frames: int) -> List[int]:
break
if int(tag) != ItemTag:
fp.seek(initial_position, 0)
raise IOError(
raise OSError(
'Building Basic Offset Table (BOT) failed. '
f'Expected tag of Frame item #{i} at position {frame_position}.'
)
length = fp.read_UL()
if length % 2:
fp.seek(initial_position, 0)
raise IOError(
raise OSError(
'Building Basic Offset Table (BOT) failed. '
f'Length of Frame item #{i} is not a multiple of 2.'
)
elif length == 0:
fp.seek(initial_position, 0)
raise IOError(
raise OSError(
'Building Basic Offset Table (BOT) failed. '
f'Length of Frame item #{i} is zero.'
)
Expand Down Expand Up @@ -299,7 +299,7 @@ def open(self) -> None:
When file cannot be found
OSError
When file cannot be opened
IOError
OSError
When DICOM metadata cannot be read from file
ValueError
When DICOM dataset contained in file does not represent an image
Expand Down Expand Up @@ -373,12 +373,12 @@ def _read_metadata(self) -> None:
"""
logger.debug('read metadata elements')
if self._fp is None:
raise IOError('File has not been opened for reading.')
raise OSError('File has not been opened for reading.')

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

# Cache Transfer Syntax UID, since we need it to decode frame items
self._transfer_syntax_uid = UID(metadata.file_meta.TransferSyntaxUID)
Expand Down Expand Up @@ -413,7 +413,7 @@ def _read_metadata(self) -> None:
try:
self._basic_offset_table = _get_bot(self._fp, number_of_frames)
except Exception as err:
raise IOError(f'Failed to build Basic Offset Table: "{err}"')
raise OSError(f'Failed to build Basic Offset Table: "{err}"')
self._first_frame_offset = self._fp.tell()
else:
if self._fp.is_implicit_VR:
Expand Down Expand Up @@ -516,7 +516,7 @@ def read_frame_raw(self, index: int) -> bytes:
Raises
------
IOError
OSError
When frame could not be read
"""
Expand Down Expand Up @@ -549,7 +549,7 @@ def read_frame_raw(self, index: int) -> bytes:
frame_data = self._fp.read(self._bytes_per_frame_uncompressed)

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

return frame_data

Expand All @@ -574,7 +574,7 @@ def read_frame(self, index: int, correct_color: bool = True) -> np.ndarray:
Raises
------
IOError
OSError
When frame could not be read
"""
Expand Down

0 comments on commit bc565c0

Please sign in to comment.