KF8 Input: Do not error out if the file has a few invalidly encoded bytes. Fixes #997034 (Book opening after import stops with invalid continuation byte)

This commit is contained in:
Kovid Goyal 2012-05-09 22:18:06 +05:30
parent 38747f1d3f
commit d6c69c8579
2 changed files with 7 additions and 3 deletions

View File

@ -111,7 +111,11 @@ def update_flow_links(mobi8_reader, resource_map, log):
continue
if not isinstance(flow, unicode):
try:
flow = flow.decode(mr.header.codec)
except UnicodeDecodeError:
log.error('Flow part has invalid %s encoded bytes'%mr.header.codec)
flow = flow.decode(mr.header.codec, 'replace')
# links to raster image files from image tags
# image_pattern

View File

@ -207,9 +207,9 @@ class Mobi8Reader(object):
fname = 'svgimg' + nstr + '.svg'
else:
# search for CDATA and if exists inline it
if flowpart.find('[CDATA[') >= 0:
if flowpart.find(b'[CDATA[') >= 0:
typ = 'css'
flowpart = '<style type="text/css">\n' + flowpart + '\n</style>\n'
flowpart = b'<style type="text/css">\n' + flowpart + b'\n</style>\n'
format = 'inline'
dir = None
fname = None