aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Baumgartner <dev@igsor.net>2023-02-08 19:24:37 +0100
committerMatthias Baumgartner <dev@igsor.net>2023-02-08 19:24:37 +0100
commit0d0144466919cfb168e75c2af26d5cb74e10bfa0 (patch)
treed280d9d1e19e4f7a9d0d4b5405603c729e1fdcce
parenta281d6b3a75a7d4a97e673c285ee430a327482ed (diff)
downloadbsie-0d0144466919cfb168e75c2af26d5cb74e10bfa0.tar.gz
bsie-0d0144466919cfb168e75c2af26d5cb74e10bfa0.tar.bz2
bsie-0d0144466919cfb168e75c2af26d5cb74e10bfa0.zip
minor cleanup
-rw-r--r--bsie/extractor/image/colors_spatial.py2
-rw-r--r--bsie/reader/chain.py11
-rw-r--r--bsie/reader/image/__init__.py1
-rw-r--r--bsie/reader/image/_pillow.py2
-rw-r--r--bsie/reader/image/_raw.py6
5 files changed, 12 insertions, 10 deletions
diff --git a/bsie/extractor/image/colors_spatial.py b/bsie/extractor/image/colors_spatial.py
index ce5b9f2..15fd281 100644
--- a/bsie/extractor/image/colors_spatial.py
+++ b/bsie/extractor/image/colors_spatial.py
@@ -120,7 +120,7 @@ class ColorsSpatial(base.Extractor):
def extract(
self,
subject: node.Node,
- content: PIL.Image,
+ content: PIL.Image.Image,
principals: typing.Iterable[bsfs.schema.Predicate],
) -> typing.Iterator[typing.Tuple[node.Node, bsfs.schema.Predicate, typing.Any]]:
# check principals
diff --git a/bsie/reader/chain.py b/bsie/reader/chain.py
index 5e9e0d5..1dbc52b 100644
--- a/bsie/reader/chain.py
+++ b/bsie/reader/chain.py
@@ -73,16 +73,19 @@ class ReaderChain(base.Reader, typing.Generic[T_CONTENT]):
return hash((super().__hash__(), self._children))
def __call__(self, path: str) -> T_CONTENT:
- raise_error = errors.UnsupportedFileFormatError
+ raise_error = False
for child in self._children:
try:
return child(path)
except errors.UnsupportedFileFormatError:
+ # child cannot read the file, skip.
pass
except errors.ReaderError:
- # child cannot read the file, skip.
- raise_error = errors.ReaderError # type: ignore [assignment] # mypy is confused
+ # child failed to read the file, skip.
+ raise_error = True
- raise raise_error(path)
+ if raise_error:
+ raise errors.ReaderError(path)
+ raise errors.UnsupportedFileFormatError(path)
## EOF ##
diff --git a/bsie/reader/image/__init__.py b/bsie/reader/image/__init__.py
index 1f290b5..c5d2a2a 100644
--- a/bsie/reader/image/__init__.py
+++ b/bsie/reader/image/__init__.py
@@ -27,7 +27,6 @@ __all__: typing.Sequence[str] = (
## code ##
-# FIXME: Check if PIL.Image or PIL.Image.Image, or if version-dependent
class Image(chain.ReaderChain[PIL.Image.Image]): # pylint: disable=too-few-public-methods
"""Read an image file."""
diff --git a/bsie/reader/image/_pillow.py b/bsie/reader/image/_pillow.py
index 3144509..5b2bdf2 100644
--- a/bsie/reader/image/_pillow.py
+++ b/bsie/reader/image/_pillow.py
@@ -27,7 +27,7 @@ __all__: typing.Sequence[str] = (
class PillowImage(base.Reader):
"""Use PIL to read content of a variety of image file types."""
- def __call__(self, path: str) -> PIL.Image:
+ def __call__(self, path: str) -> PIL.Image.Image:
try:
# open file with PIL
return PIL.Image.open(path)
diff --git a/bsie/reader/image/_raw.py b/bsie/reader/image/_raw.py
index cd60453..257fdb3 100644
--- a/bsie/reader/image/_raw.py
+++ b/bsie/reader/image/_raw.py
@@ -32,17 +32,17 @@ class RawImage(base.Reader):
"""Use rawpy to read content of raw image file types."""
# file matcher
- match: filematcher.Matcher
+ _match: filematcher.Matcher
# additional kwargs to rawpy's postprocess
- rawpy_kwargs: typing.Dict[str, typing.Any]
+ _rawpy_kwargs: typing.Dict[str, typing.Any]
def __init__(self, **rawpy_kwargs):
match_rule = rawpy_kwargs.pop('file_match_rule', MATCH_RULE)
self._match = filematcher.parse(match_rule)
self._rawpy_kwargs = rawpy_kwargs
- def __call__(self, path: str) -> PIL.Image:
+ def __call__(self, path: str) -> PIL.Image.Image:
# perform quick checks first
if not self._match(path):
raise errors.UnsupportedFileFormatError(path)