mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #908 (Error message when converting LIT file)
This commit is contained in:
commit
4f4af05fa2
@ -93,6 +93,10 @@ def read_utf8_char(bytes, pos):
|
|||||||
c = (c << 6) | (b & 0x3F)
|
c = (c << 6) | (b & 0x3F)
|
||||||
return unichr(c), pos+elsize
|
return unichr(c), pos+elsize
|
||||||
|
|
||||||
|
def consume_utf8_length(bytes):
|
||||||
|
char, elsize = read_utf8_char(bytes, 0)
|
||||||
|
return ord(char), bytes[elsize:]
|
||||||
|
|
||||||
class UnBinary(object):
|
class UnBinary(object):
|
||||||
AMPERSAND_RE = re.compile(
|
AMPERSAND_RE = re.compile(
|
||||||
r'&(?!(?:#[0-9]+|#x[0-9a-fA-F]+|[a-zA-Z_:][a-zA-Z0-9.-_:]+);)')
|
r'&(?!(?:#[0-9]+|#x[0-9a-fA-F]+|[a-zA-Z_:][a-zA-Z0-9.-_:]+);)')
|
||||||
@ -315,8 +319,11 @@ class ManifestItem(object):
|
|||||||
self.offset = offset
|
self.offset = offset
|
||||||
self.root = root
|
self.root = root
|
||||||
self.state = state
|
self.state = state
|
||||||
|
# Some LIT files have Windows-style paths
|
||||||
|
path = original.replace('\\', '/')
|
||||||
|
if path[1:3] == ':/': path = path[2:]
|
||||||
# Some paths in Fictionwise "multiformat" LIT files contain '..' (!?)
|
# Some paths in Fictionwise "multiformat" LIT files contain '..' (!?)
|
||||||
path = os.path.normpath(original).replace('\\', '/')
|
path = os.path.normpath(path).replace('\\', '/')
|
||||||
while path.startswith('../'): path = path[3:]
|
while path.startswith('../'): path = path[3:]
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
@ -557,14 +564,15 @@ class LitReader(object):
|
|||||||
if len(raw) < 5:
|
if len(raw) < 5:
|
||||||
raise LitError('Truncated manifest')
|
raise LitError('Truncated manifest')
|
||||||
offset, raw = u32(raw), raw[4:]
|
offset, raw = u32(raw), raw[4:]
|
||||||
slen, raw = ord(raw[0]), raw[1:]
|
slen, raw = consume_utf8_length(raw)
|
||||||
internal, raw = raw[:slen].decode('utf8'), raw[slen:]
|
internal, raw = raw[:slen].decode('utf8'), raw[slen:]
|
||||||
slen, raw = ord(raw[0]), raw[1:]
|
slen, raw = consume_utf8_length(raw)
|
||||||
original, raw = raw[:slen].decode('utf8'), raw[slen:]
|
original, raw = raw[:slen].decode('utf8'), raw[slen:]
|
||||||
slen, raw = ord(raw[0]), raw[1:]
|
slen, raw = consume_utf8_length(raw)
|
||||||
mime_type, raw = raw[:slen].decode('utf8'), raw[slen+1:]
|
mime_type, raw = raw[:slen].decode('utf8'), raw[slen+1:]
|
||||||
self.manifest[internal] = ManifestItem(
|
self.manifest[internal] = ManifestItem(
|
||||||
original, internal, mime_type, offset, root, state)
|
original, internal, mime_type, offset, root, state)
|
||||||
|
# Remove any common path elements
|
||||||
mlist = self.manifest.values()
|
mlist = self.manifest.values()
|
||||||
shared = mlist[0].path
|
shared = mlist[0].path
|
||||||
for item in mlist[1:]:
|
for item in mlist[1:]:
|
||||||
@ -578,6 +586,10 @@ class LitReader(object):
|
|||||||
slen = len(shared)
|
slen = len(shared)
|
||||||
for item in mlist:
|
for item in mlist:
|
||||||
item.path = item.path[slen:]
|
item.path = item.path[slen:]
|
||||||
|
# Fix any straggling absolute paths
|
||||||
|
for item in mlist:
|
||||||
|
if item.path[0] == '/':
|
||||||
|
item.path = os.path.basename(item.path)
|
||||||
|
|
||||||
def _read_meta(self):
|
def _read_meta(self):
|
||||||
raw = self.get_file('/meta')
|
raw = self.get_file('/meta')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user