mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:...
This commit is contained in:
commit
f96e9cce0c
@ -47,7 +47,6 @@ FLAG_CLOSING = (1 << 1)
|
|||||||
FLAG_BLOCK = (1 << 2)
|
FLAG_BLOCK = (1 << 2)
|
||||||
FLAG_HEAD = (1 << 3)
|
FLAG_HEAD = (1 << 3)
|
||||||
FLAG_ATOM = (1 << 4)
|
FLAG_ATOM = (1 << 4)
|
||||||
XML_ENTITIES = ['&', ''', '<', '>', '"']
|
|
||||||
|
|
||||||
def u32(bytes):
|
def u32(bytes):
|
||||||
return struct.unpack('<L', bytes[:4])[0]
|
return struct.unpack('<L', bytes[:4])[0]
|
||||||
@ -114,7 +113,7 @@ class UnBinary(object):
|
|||||||
CLOSE_ANGLE_RE = re.compile(r'(?<!--)>>')
|
CLOSE_ANGLE_RE = re.compile(r'(?<!--)>>')
|
||||||
DOUBLE_ANGLE_RE = re.compile(r'([<>])\1')
|
DOUBLE_ANGLE_RE = re.compile(r'([<>])\1')
|
||||||
|
|
||||||
def __init__(self, bin, path, manifest, map=OPF_MAP):
|
def __init__(self, bin, path, manifest={}, map=HTML_MAP):
|
||||||
self.manifest = manifest
|
self.manifest = manifest
|
||||||
self.tag_map, self.attr_map, self.tag_to_attr_map = map
|
self.tag_map, self.attr_map, self.tag_to_attr_map = map
|
||||||
self.opf = map is OPF_MAP
|
self.opf = map is OPF_MAP
|
||||||
@ -123,7 +122,7 @@ class UnBinary(object):
|
|||||||
self.buf = cStringIO.StringIO()
|
self.buf = cStringIO.StringIO()
|
||||||
self.binary_to_text()
|
self.binary_to_text()
|
||||||
self.raw = self.buf.getvalue().lstrip().decode('utf-8')
|
self.raw = self.buf.getvalue().lstrip().decode('utf-8')
|
||||||
self.escape_reserved()
|
self.escape_reserved()
|
||||||
|
|
||||||
def escape_reserved(self):
|
def escape_reserved(self):
|
||||||
raw = self.raw
|
raw = self.raw
|
||||||
@ -157,7 +156,7 @@ class UnBinary(object):
|
|||||||
dynamic_tag = errors = 0
|
dynamic_tag = errors = 0
|
||||||
in_censorship = is_goingdown = False
|
in_censorship = is_goingdown = False
|
||||||
state = 'text'
|
state = 'text'
|
||||||
index = base
|
index = base
|
||||||
flags = 0
|
flags = 0
|
||||||
|
|
||||||
while index < len(self.bin):
|
while index < len(self.bin):
|
||||||
@ -368,8 +367,10 @@ class ManifestItem(object):
|
|||||||
return self.internal == other
|
return self.internal == other
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "ManifestItem(internal=%s, path=%s)" \
|
return "ManifestItem(internal=%r, path=%r, mime_type=%r, " \
|
||||||
% (repr(self.internal), repr(self.path))
|
"offset=%d, root=%r, state=%r)" \
|
||||||
|
% (self.internal, self.path, self.mime_type, self.offset,
|
||||||
|
self.root, self.state)
|
||||||
|
|
||||||
def preserve(function):
|
def preserve(function):
|
||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
@ -442,7 +443,7 @@ class LitReader(object):
|
|||||||
self._stream.seek(0)
|
self._stream.seek(0)
|
||||||
return self._stream.read(size)
|
return self._stream.read(size)
|
||||||
return property(fget=fget)
|
return property(fget=fget)
|
||||||
header = header()
|
header = header()
|
||||||
|
|
||||||
def __init__(self, filename_or_stream):
|
def __init__(self, filename_or_stream):
|
||||||
if hasattr(filename_or_stream, 'read'):
|
if hasattr(filename_or_stream, 'read'):
|
||||||
@ -452,7 +453,7 @@ class LitReader(object):
|
|||||||
if self.magic != 'ITOLITLS':
|
if self.magic != 'ITOLITLS':
|
||||||
raise LitError('Not a valid LIT file')
|
raise LitError('Not a valid LIT file')
|
||||||
if self.version != 1:
|
if self.version != 1:
|
||||||
raise LitError('Unknown LIT version %d'%(self.version,))
|
raise LitError('Unknown LIT version %d' % (self.version,))
|
||||||
self.entries = {}
|
self.entries = {}
|
||||||
self._read_secondary_header()
|
self._read_secondary_header()
|
||||||
self._read_header_pieces()
|
self._read_header_pieces()
|
||||||
@ -641,14 +642,15 @@ class LitReader(object):
|
|||||||
def _read_meta(self):
|
def _read_meta(self):
|
||||||
path = 'content.opf'
|
path = 'content.opf'
|
||||||
raw = self.get_file('/meta')
|
raw = self.get_file('/meta')
|
||||||
|
xml = OPF_DECL
|
||||||
try:
|
try:
|
||||||
xml = OPF_DECL + unicode(UnBinary(raw, path, self.manifest, OPF_MAP))
|
xml += unicode(UnBinary(raw, path, self.manifest, OPF_MAP))
|
||||||
except LitError:
|
except LitError:
|
||||||
if 'PENGUIN group' not in raw: raise
|
if 'PENGUIN group' not in raw: raise
|
||||||
print "WARNING: attempting PENGUIN malformed OPF fix"
|
print "WARNING: attempting PENGUIN malformed OPF fix"
|
||||||
raw = raw.replace(
|
raw = raw.replace(
|
||||||
'PENGUIN group', '\x00\x01\x18\x00PENGUIN group', 1)
|
'PENGUIN group', '\x00\x01\x18\x00PENGUIN group', 1)
|
||||||
xml = OPF_DECL + unicode(UnBinary(raw, path, self.manifest, OPF_MAP))
|
xml += unicode(UnBinary(raw, path, self.manifest, OPF_MAP))
|
||||||
self.meta = xml
|
self.meta = xml
|
||||||
|
|
||||||
def _read_drm(self):
|
def _read_drm(self):
|
||||||
@ -668,7 +670,7 @@ class LitReader(object):
|
|||||||
raise LitError('Unable to decrypt title key!')
|
raise LitError('Unable to decrypt title key!')
|
||||||
self.bookkey = bookkey[1:9]
|
self.bookkey = bookkey[1:9]
|
||||||
else:
|
else:
|
||||||
raise DRMError()
|
raise DRMError("Cannot access DRM-protected book")
|
||||||
|
|
||||||
def _calculate_deskey(self):
|
def _calculate_deskey(self):
|
||||||
hashfiles = ['/meta', '/DRMStorage/DRMSource']
|
hashfiles = ['/meta', '/DRMStorage/DRMSource']
|
||||||
@ -731,6 +733,11 @@ class LitReader(object):
|
|||||||
return content
|
return content
|
||||||
|
|
||||||
def _decrypt(self, content):
|
def _decrypt(self, content):
|
||||||
|
length = len(content)
|
||||||
|
extra = length & 0x7
|
||||||
|
if extra > 0:
|
||||||
|
self._warn("content length not a multiple of block size")
|
||||||
|
content += "\0" * (8 - extra)
|
||||||
msdes.deskey(self.bookkey, msdes.DE1)
|
msdes.deskey(self.bookkey, msdes.DE1)
|
||||||
return msdes.des(content)
|
return msdes.des(content)
|
||||||
|
|
||||||
@ -768,7 +775,7 @@ class LitReader(object):
|
|||||||
if u != 0:
|
if u != 0:
|
||||||
raise LitError("Reset table entry greater than 32 bits")
|
raise LitError("Reset table entry greater than 32 bits")
|
||||||
if size >= len(content):
|
if size >= len(content):
|
||||||
raise("Reset table entry out of bounds")
|
raise LitError("Reset table entry out of bounds")
|
||||||
if bytes_remaining >= window_bytes:
|
if bytes_remaining >= window_bytes:
|
||||||
lzx.reset()
|
lzx.reset()
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user