Skip to content

Commit 251c899

Browse files
committed
WIP: generalize class for opening image
Allow FileHolder subclasses to change the ImageOpener class.
1 parent c445edd commit 251c899

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

nibabel/fileholders.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ class FileHolderError(Exception):
2323
class FileHolder:
2424
"""class to contain filename, fileobj and file position"""
2525

26+
# Default image opener class / callable
27+
make_image_opener = ImageOpener
28+
2629
def __init__(
2730
self,
2831
filename: str | None = None,
@@ -68,10 +71,11 @@ def get_prepare_fileobj(self, *args, **kwargs) -> ImageOpener:
6871
``self.pos``
6972
"""
7073
if self.fileobj is not None:
71-
obj = ImageOpener(self.fileobj) # for context manager
74+
# for context manager
75+
obj = self.make_image_opener(self.fileobj)
7276
obj.seek(self.pos)
7377
elif self.filename is not None:
74-
obj = ImageOpener(self.filename, *args, **kwargs)
78+
obj = self.make_image_opener(self.filename, *args, **kwargs)
7579
if self.pos != 0:
7680
obj.seek(self.pos)
7781
else:

0 commit comments

Comments
 (0)