From f2009fd9915c9fbcd4f80b3d0b7125739b7b7293 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 22 Apr 2019 03:20:59 -0400 Subject: [PATCH 1/3] py3: make rb output work --- src/calibre/ebooks/rb/__init__.py | 2 +- src/calibre/ebooks/rb/writer.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/calibre/ebooks/rb/__init__.py b/src/calibre/ebooks/rb/__init__.py index acf9c04995..f45b966dad 100644 --- a/src/calibre/ebooks/rb/__init__.py +++ b/src/calibre/ebooks/rb/__init__.py @@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en' import os -HEADER = '\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' +HEADER = b'\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' class RocketBookError(Exception): diff --git a/src/calibre/ebooks/rb/writer.py b/src/calibre/ebooks/rb/writer.py index dc83476b39..9f4818725f 100644 --- a/src/calibre/ebooks/rb/writer.py +++ b/src/calibre/ebooks/rb/writer.py @@ -73,13 +73,13 @@ class RBWriter(object): out_stream.write(struct.pack(' Date: Mon, 29 Apr 2019 01:52:41 -0400 Subject: [PATCH 2/3] py3: make rb input work --- src/calibre/ebooks/rb/reader.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/rb/reader.py b/src/calibre/ebooks/rb/reader.py index da5330c7f1..0d111107fa 100644 --- a/src/calibre/ebooks/rb/reader.py +++ b/src/calibre/ebooks/rb/reader.py @@ -64,7 +64,7 @@ class Reader(object): toc = RBToc() for i in range(pages): - name = unquote(self.stream.read(32).strip('\x00')) + name = unquote(self.stream.read(32).strip(b'\x00')) size, offset, flags = self.read_i32(), self.read_i32(), self.read_i32() toc.append(RBToc.Item(name=name, size=size, offset=offset, flags=flags)) @@ -90,7 +90,7 @@ class Reader(object): else: output += self.stream.read(toc_item.size).decode('cp1252' if self.encoding is None else self.encoding, 'replace') - with open(os.path.join(output_dir, toc_item.name), 'wb') as html: + with open(os.path.join(output_dir, toc_item.name.decode('utf-8')), 'wb') as html: html.write(output.replace('', '<TITLE> ').encode('utf-8')) def get_image(self, toc_item, output_dir): @@ -100,7 +100,7 @@ class Reader(object): self.stream.seek(toc_item.offset) data = self.stream.read(toc_item.size) - with open(os.path.join(output_dir, toc_item.name), 'wb') as img: + with open(os.path.join(output_dir, toc_item.name.decode('utf-8')), 'wb') as img: img.write(data) def extract_content(self, output_dir): @@ -109,13 +109,14 @@ class Reader(object): images = [] for item in self.toc: - if item.name.lower().endswith('html'): - self.log.debug('HTML item %s found...' % item.name) - html.append(item.name) + iname = item.name.decode('utf-8') + if iname.lower().endswith('html'): + self.log.debug('HTML item %s found...' % iname) + html.append(iname) self.get_text(item, output_dir) - if item.name.lower().endswith('png'): - self.log.debug('PNG item %s found...' % item.name) - images.append(item.name) + if iname.lower().endswith('png'): + self.log.debug('PNG item %s found...' % iname) + images.append(iname) self.get_image(item, output_dir) opf_path = self.create_opf(output_dir, html, images) From c478c978ef3211755dc1cdea5e398929b81fb7a2 Mon Sep 17 00:00:00 2001 From: Eli Schwartz <eschwartz@archlinux.org> Date: Mon, 29 Apr 2019 02:02:36 -0400 Subject: [PATCH 3/3] py3: make rb metadata reading work --- src/calibre/ebooks/metadata/rb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/calibre/ebooks/metadata/rb.py b/src/calibre/ebooks/metadata/rb.py index a193ae44d9..7f5ad0b5c4 100644 --- a/src/calibre/ebooks/metadata/rb.py +++ b/src/calibre/ebooks/metadata/rb.py @@ -8,7 +8,7 @@ import sys, struct from calibre.ebooks.metadata import MetaInformation, string_to_authors from polyglot.builtins import unicode_type -MAGIC = '\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' +MAGIC = b'\xb0\x0c\xb0\x0c\x02\x00NUVO\x00\x00\x00\x00' def get_metadata(stream): @@ -37,7 +37,7 @@ def get_metadata(stream): return mi stream.seek(offset) - info = stream.read(length).splitlines() + info = stream.read(length).decode().splitlines() for line in info: if '=' not in line: continue