aerkalov/ebooklib

Can't load epubs from ZipExtFile

ascendant512 opened this issue · 0 comments

Hi,
I encountered a regression from 0.17.1 -> 0.18 in that the library crashes if it's fed a ZipExtFile object.
The crash is here:

if os.path.isdir(self.file_name):

File ".../venv/lib/python3.10/site-packages/ebooklib/epub.py", line 1700, in _load
    if os.path.isdir(self.file_name):
  File "/usr/lib/python-exec/python3.10/../../../lib/python3.10/genericpath.py", line 42, in isdir
    st = os.stat(s)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not ZipExtFile

To clarify, my script opens a zip file with zipfile.ZipFile in the standard library, and then opens .epub files inside the zip file with ZipFile.open()
You might be able to say it's a bug in os.stat.isdir() since it's definitely not a dir 😄. But, it would be nice if you could catch TypeError and then treat the input as a file and not a directory.