From 8c6698abf7e7c7f28d3ceda7ca83bfb9dcbd1297 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 10 Apr 2019 13:20:50 -0400 Subject: [PATCH 1/2] py3: decode uuid4().hex using python3-compatible syntax Also skip the additional uuid import, as it is already imported at the top of the file. --- src/calibre/ebooks/mobi/reader/mobi8.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/mobi/reader/mobi8.py b/src/calibre/ebooks/mobi/reader/mobi8.py index 07d72f1d36..228280e0eb 100644 --- a/src/calibre/ebooks/mobi/reader/mobi8.py +++ b/src/calibre/ebooks/mobi/reader/mobi8.py @@ -85,7 +85,7 @@ class Mobi8Reader(object): def __call__(self): self.mobi6_reader.check_for_drm() - self.aid_anchor_suffix = bytes(uuid4().hex) + self.aid_anchor_suffix = uuid4().hex.encode('utf-8') bh = self.mobi6_reader.book_header if self.mobi6_reader.kf8_type == 'joint': offset = self.mobi6_reader.kf8_boundary + 2 @@ -225,8 +225,7 @@ class Mobi8Reader(object): self.parts.append(skeleton) if divcnt < 1: # Empty file - import uuid - aidtext = str(uuid.uuid4()) + aidtext = str(uuid4()) filename = aidtext + '.html' self.partinfo.append(Part(skelnum, 'text', filename, skelpos, baseptr, aidtext)) From 92052e79d4138e66350d47ff3225eccca048a11b Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Wed, 10 Apr 2019 13:29:55 -0400 Subject: [PATCH 2/2] py3: miscellaneous strings need to be marked as bytes --- src/calibre/ebooks/mobi/reader/mobi6.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/mobi/reader/mobi6.py b/src/calibre/ebooks/mobi/reader/mobi6.py index 5a21510465..5910423855 100644 --- a/src/calibre/ebooks/mobi/reader/mobi6.py +++ b/src/calibre/ebooks/mobi/reader/mobi6.py @@ -79,17 +79,17 @@ class MobiReader(object): stream = open(filename_or_stream, 'rb') raw = stream.read() - if raw.startswith('TPZ'): + if raw.startswith(b'TPZ'): raise TopazError(_('This is an Amazon Topaz book. It cannot be processed.')) if raw.startswith(b'\xeaDRMION\xee'): raise KFXError() self.header = raw[0:72] - self.name = self.header[:32].replace('\x00', '') + self.name = self.header[:32].replace(b'\x00', b'') self.num_sections, = struct.unpack('>H', raw[76:78]) self.ident = self.header[0x3C:0x3C + 8].upper() - if self.ident not in ['BOOKMOBI', 'TEXTREAD']: + if self.ident not in [b'BOOKMOBI', b'TEXTREAD']: raise MobiError('Unknown book type: %s' % repr(self.ident)) self.sections = []