mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'py3' of https://github.com/eli-schwartz/calibre
This commit is contained in:
commit
116ef1cc4d
@ -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)
|
||||
|
||||
|
||||
|
@ -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])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user