Skip to content

Commit

Permalink
Merge pull request #1162 from girder/rename-tiff-exceptions
Browse files Browse the repository at this point in the history
Rename tiff exceptions to be better follow python standards
  • Loading branch information
manthey authored May 22, 2023
2 parents 81649cd + 796ce92 commit af524dc
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 110 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Change Log

## 1.20.7
## 1.21.0

### Improvements
- getPixel method and endpoint now returns rawer values ([#1155](../../pull/1155))
- Allow more sophisticated filtering on item lists from the Girder client ([#1157](../../pull/1157), [#1159](../../pull/1159))
- Allow more sophisticated filtering on item lists from the Girder client ([#1157](../../pull/1157), [#1159](../../pull/1159), [#1161](../../pull/1161))

### Changes
- Rename tiff exceptions to be better follow python standards ([#1162](../../pull/1162))

### Bug Fixes
- The deepzoom tile source misreported the format of its tile output ([#1158](../../pull/1158))
Expand Down
12 changes: 5 additions & 7 deletions sources/ometiff/large_image_source_ometiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
import numpy
import PIL.Image
from large_image_source_tiff import TiffFileTileSource
from large_image_source_tiff.tiff_reader import (InvalidOperationTiffException,
IOTiffException,
TiffException,
TiledTiffDirectory)
from large_image_source_tiff.exceptions import InvalidOperationTiffError, IOTiffError, TiffError
from large_image_source_tiff.tiff_reader import TiledTiffDirectory

from large_image.cache_util import LruCacheMetaclass, methodcache
from large_image.constants import TILE_FORMAT_NUMPY, TILE_FORMAT_PIL, SourcePriority
Expand Down Expand Up @@ -102,7 +100,7 @@ def __init__(self, path, **kwargs):

try:
base = TiledTiffDirectory(self._largeImagePath, 0, mustBeTiled=None)
except TiffException:
except TiffError:
if not os.path.isfile(self._largeImagePath):
raise TileSourceFileNotFoundError(self._largeImagePath) from None
raise TileSourceError('Not a recognized OME Tiff')
Expand Down Expand Up @@ -355,9 +353,9 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False,
format = TILE_FORMAT_NUMPY
return self._outputTile(tile, format, x, y, z, pilImageAllowed,
numpyAllowed, **kwargs)
except InvalidOperationTiffException as e:
except InvalidOperationTiffError as e:
raise TileSourceError(e.args[0])
except IOTiffException as e:
except IOTiffError as e:
return self.getTileIOTiffError(
x, y, z, pilImageAllowed=pilImageAllowed,
numpyAllowed=numpyAllowed, sparseFallback=sparseFallback,
Expand Down
26 changes: 13 additions & 13 deletions sources/tiff/large_image_source_tiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
from large_image.exceptions import TileSourceError, TileSourceFileNotFoundError
from large_image.tilesource import FileTileSource, nearPowerOfTwo

from .tiff_reader import (InvalidOperationTiffException, IOTiffException,
IOTiffOpenException, TiffException,
TiledTiffDirectory, ValidationTiffException)
from .exceptions import (InvalidOperationTiffError, IOOpenTiffError,
IOTiffError, TiffError, ValidationTiffError)
from .tiff_reader import TiledTiffDirectory

try:
from importlib.metadata import PackageNotFoundError
Expand Down Expand Up @@ -105,9 +105,9 @@ def __init__(self, path, **kwargs): # noqa

try:
alldir = self._scanDirectories()
except IOTiffOpenException:
except IOOpenTiffError:
raise TileSourceError('File cannot be opened via tiff source.')
except (ValidationTiffException, TiffException) as exc:
except (ValidationTiffError, TiffError) as exc:
alldir = []
lastException = exc

Expand Down Expand Up @@ -193,11 +193,11 @@ def _scanDirectories(self):
dir._setDirectory(directoryNum)
dir._loadMetadata()
dir._validate()
except ValidationTiffException as exc:
except ValidationTiffError as exc:
lastException = exc
associatedDirs.append(directoryNum)
continue
except TiffException as exc:
except TiffError as exc:
if not lastException:
lastException = exc
break
Expand Down Expand Up @@ -438,7 +438,7 @@ def _addAssociatedImage(self, largeImagePath, directoryNum, mustBeTiled=False, t
return
image = self._reorient_numpy_image(image, associated._tiffInfo.get('orientation'))
self._associatedImages[id] = image
except (TiffException, AttributeError):
except (TiffError, AttributeError):
# If we can't validate or read an associated image or it has no
# useful imagedescription, fail quietly without adding an
# associated image.
Expand Down Expand Up @@ -582,10 +582,10 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False,
if not kwargs.get('inSparseFallback'):
tile = self.getTileFromEmptyDirectory(x, y, z, **kwargs)
else:
raise IOTiffException('Missing z level %d' % z)
raise IOTiffError('Missing z level %d' % z)
except Exception:
if sparseFallback:
raise IOTiffException('Missing z level %d' % z)
raise IOTiffError('Missing z level %d' % z)
else:
raise
allowStyle = False
Expand All @@ -599,9 +599,9 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False,
format = TILE_FORMAT_NUMPY
return self._outputTile(tile, format, x, y, z, pilImageAllowed,
numpyAllowed, applyStyle=allowStyle, **kwargs)
except InvalidOperationTiffException as e:
except InvalidOperationTiffError as e:
raise TileSourceError(e.args[0])
except IOTiffException as e:
except IOTiffError as e:
return self.getTileIOTiffError(
x, y, z, pilImageAllowed=pilImageAllowed,
numpyAllowed=numpyAllowed, sparseFallback=sparseFallback,
Expand All @@ -619,7 +619,7 @@ def _getDirFromCache(self, dirnum, subdir=None):
try:
result = TiledTiffDirectory(
self._largeImagePath, dirnum, mustBeTiled=None, subDirectoryNum=subdir)
except IOTiffException:
except IOTiffError:
result = None
self._directoryCache[key] = result
return result
Expand Down
37 changes: 37 additions & 0 deletions sources/tiff/large_image_source_tiff/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class TiffError(Exception):
pass


class InvalidOperationTiffError(TiffError):
"""
An exception caused by the user making an invalid request of a TIFF file.
"""

pass


class IOTiffError(TiffError):
"""
An exception caused by an internal failure, due to an invalid file or other
error.
"""

pass


class IOOpenTiffError(IOTiffError):
"""
An exception caused by an internal failure where the file cannot be opened
by the main library.
"""

pass


class ValidationTiffError(TiffError):
"""
An exception caused by the TIFF reader not being able to support a given
file.
"""

pass
Loading

0 comments on commit af524dc

Please sign in to comment.