diff options
author | benadha <benawiadha@gmail.com> | 2022-01-05 19:17:32 +0700 |
---|---|---|
committer | benadha <benawiadha@gmail.com> | 2022-01-05 19:17:32 +0700 |
commit | 1c69181d2477c1ae4446241f282a706705cdc4d7 (patch) | |
tree | b6a0331d1e474f6098489bda133dc8d1622a9d8b | |
parent | 07f2cfedc47387ea4d7cf3b5ab435a971f7c6f02 (diff) | |
download | epy-1c69181d2477c1ae4446241f282a706705cdc4d7.tar.gz |
Fix path resolver for Mobi.get_img_bytstr()
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | epy.py | 6 |
2 files changed, 6 insertions, 1 deletions
@@ -4,3 +4,4 @@ epy_reader.egg-info/* .idea build dist +tmp/ @@ -644,7 +644,9 @@ class Mobi(Epub): def get_img_bytestr(self, impath: str) -> Tuple[str, bytes]: # TODO: test on windows # if impath "Images/asdf.png" is problematic - with open(os.path.join(self.root_dirpath, impath), "rb") as f: + image_abspath = os.path.join(self.root_dirpath, impath) + image_abspath = os.path.normpath(image_abspath) # handle crossplatform path + with open(image_abspath, "rb") as f: src = f.read() return impath, src @@ -1714,6 +1716,8 @@ def resolve_path(current_dir: str, relative_path: str) -> str: eg. '/foo/bar/book.html' + '../img.png' = '/foo/img.png' NOTE: '/' suffix is important to tell that current dir in 'bar' """ + # can also using os.path.normpath() + # but if the image in zipfile then posix path is mandatory return urljoin(current_dir, relative_path) |