Skip to content

Commit 4279d6a

Browse files
src/__init__.py: Document constructor: simplified handling of temporary Archive.
1 parent e91c0a2 commit 4279d6a

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

src/__init__.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,13 +2947,10 @@ def __init__(self, filename=None, stream=None, filetype=None, archive=None, rect
29472947
archive = Archive(archive.name)
29482948
elif isinstance(archive, str):
29492949
archive = Archive(archive)
2950-
if archive and not isinstance(archive, Archive):
2951-
raise TypeError(f"bad archive: {type(archive)=}.")
2952-
if archive:
2953-
archive_parm = archive.this # pass this to open
2954-
else:
2950+
elif not archive:
29552951
archive = Archive()
2956-
archive_parm = archive.this
2952+
elif not isinstance(archive, Archive):
2953+
raise TypeError(f"bad archive: {type(archive)=}.")
29572954
if stream is not None:
29582955
if filename is not None and filetype is None:
29592956
# 2025-05-06: Use <filename> as the filetype. This is
@@ -2981,7 +2978,7 @@ def __init__(self, filename=None, stream=None, filetype=None, archive=None, rect
29812978

29822979
fz_stream = mupdf.fz_open_memory(mupdf.python_buffer_data(stream), len(stream))
29832980
try:
2984-
doc = mupdf.fz_open_document_with_stream_and_dir(filetype if filetype else '', fz_stream, archive_parm)
2981+
doc = mupdf.fz_open_document_with_stream_and_dir(filetype if filetype else '', fz_stream, archive.this)
29852982
except Exception as e:
29862983
if g_exceptions_verbose > 1: exception_info()
29872984
raise FileDataError('Failed to open stream') from e
@@ -3013,7 +3010,7 @@ def __init__(self, filename=None, stream=None, filetype=None, archive=None, rect
30133010
suffix = pathlib.Path(filename).suffix.strip(".")
30143011
try:
30153012
fz_stream = mupdf.fz_open_file(filename)
3016-
doc = mupdf.fz_open_document_with_stream_and_dir(suffix, fz_stream, archive_parm)
3013+
doc = mupdf.fz_open_document_with_stream_and_dir(suffix, fz_stream, archive.this)
30173014
except Exception as e:
30183015
if g_exceptions_verbose > 1: exception_info()
30193016
raise FileDataError(f'Failed to open file {filename!r} as type {suffix}.') from e

0 commit comments

Comments
 (0)