py3: more fixes to the mobi format

This commit is contained in:
Eli Schwartz 2019-04-17 03:14:22 -04:00
parent a5aec9233f
commit 5402785205
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
2 changed files with 5 additions and 6 deletions

View File

@ -15,6 +15,7 @@ and igorsk.
import struct
from calibre.ebooks.mobi import MobiError
from polyglot.builtins import map
class Reader(object):
@ -34,7 +35,7 @@ class Reader(object):
assert term
maxcode = ((maxcode + 1) << (32 - codelen)) - 1
return (codelen, term, maxcode)
self.dict1 = map(dict1_unpack, struct.unpack_from(b'>256L', huff, off1))
self.dict1 = tuple(map(dict1_unpack, struct.unpack_from(b'>256L', huff, off1)))
dict2 = struct.unpack_from(b'>64L', huff, off2)
self.mincode, self.maxcode = (), ()
@ -106,5 +107,3 @@ class HuffReader(object):
def unpack(self, section):
return self.reader.unpack(section)

View File

@ -185,7 +185,7 @@ class BookHeader(object):
self.compression_type = raw[:2]
self.records, self.records_size = struct.unpack('>HH', raw[8:12])
self.encryption_type, = struct.unpack('>H', raw[12:14])
if ident == 'TEXTREAD':
if ident == b'TEXTREAD':
self.codepage = 1252
if len(raw) <= 16:
self.codec = 'cp1252'
@ -216,14 +216,14 @@ class BookHeader(object):
# 2.9?). See https://bugs.launchpad.net/bugs/1179144
max_header_length = 500 # We choose 500 for future versions of kindlegen
if (ident == 'TEXTREAD' or self.length < 0xE4 or
if (ident == b'TEXTREAD' or self.length < 0xE4 or
self.length > max_header_length or
(try_extra_data_fix and self.length == 0xE4)):
self.extra_flags = 0
else:
self.extra_flags, = struct.unpack('>H', raw[0xF2:0xF4])
if self.compression_type == 'DH':
if self.compression_type == b'DH':
self.huff_offset, self.huff_number = struct.unpack('>LL',
raw[0x70:0x78])