aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbenadha <benawiadha@gmail.com>2022-01-05 19:17:32 +0700
committerbenadha <benawiadha@gmail.com>2022-01-05 19:17:32 +0700
commit1c69181d2477c1ae4446241f282a706705cdc4d7 (patch)
treeb6a0331d1e474f6098489bda133dc8d1622a9d8b
parent07f2cfedc47387ea4d7cf3b5ab435a971f7c6f02 (diff)
downloadepy-1c69181d2477c1ae4446241f282a706705cdc4d7.tar.gz
Fix path resolver for Mobi.get_img_bytstr()
-rw-r--r--.gitignore1
-rwxr-xr-xepy.py6
2 files changed, 6 insertions, 1 deletions
diff --git a/.gitignore b/.gitignore
index 9d23584..8a94ee5 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ epy_reader.egg-info/*
.idea
build
dist
+tmp/
diff --git a/epy.py b/epy.py
index 5bf2915..0298b4f 100755
--- a/epy.py
+++ b/epy.py
@@ -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)