From adbe76079ed36eada4ff3ee3470543e13ef72ac0 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 22 Apr 2019 22:33:19 -0400 Subject: [PATCH 1/2] py3: make Check Book work when working with lxml.etree strings, everything is explicitly bytes --- src/calibre/ebooks/oeb/polish/check/opf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/polish/check/opf.py b/src/calibre/ebooks/oeb/polish/check/opf.py index 76f8418b4e..e2f6abd0e3 100644 --- a/src/calibre/ebooks/oeb/polish/check/opf.py +++ b/src/calibre/ebooks/oeb/polish/check/opf.py @@ -370,7 +370,7 @@ def check_opf(container): errors.append(IncorrectCover(container.opf_name, cover.sourceline, cover.get('content', ''))) raw = etree.tostring(cover) try: - n, c = raw.index('name="'), raw.index('content="') + n, c = raw.index(b'name="'), raw.index(b'content="') except ValueError: n = c = -1 if n > -1 and c > -1 and n > c: From bca47af4331737e8274cf27bb61ed0cab8febab7 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 22 Apr 2019 23:35:35 -0400 Subject: [PATCH 2/2] py3: make Polish Book work str() template cannot be formatted with an encoded bytestring because b''.__str__() is unuseful. So just defer encoding to right before writing. --- src/calibre/ebooks/oeb/polish/cover.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 941ef71d17..42cda86bf5 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -393,7 +393,7 @@ def create_epub_cover(container, cover_path, existing_image, options=None): titlepage_item = container.generate_item(tname, id_prefix='titlepage') titlepage = container.href_to_name(titlepage_item.get('href'), container.opf_name) - raw = templ%container.name_to_href(raster_cover, titlepage).encode('utf-8') + raw = (templ%container.name_to_href(raster_cover, titlepage)).encode('utf-8') with container.open(titlepage, 'wb') as f: f.write(raw)