From 9f65185da35b722781cb197318129da351ef08ab Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 19 May 2019 21:53:25 -0400 Subject: [PATCH] py3: make fb2 input work --- src/calibre/ebooks/conversion/plugins/fb2_input.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/conversion/plugins/fb2_input.py b/src/calibre/ebooks/conversion/plugins/fb2_input.py index 9992797e3d..d802fe2b2a 100644 --- a/src/calibre/ebooks/conversion/plugins/fb2_input.py +++ b/src/calibre/ebooks/conversion/plugins/fb2_input.py @@ -90,7 +90,8 @@ class FB2Input(InputFormatPlugin): css = re.sub(r'name\s*=\s*', 'class=', css) self.extract_embedded_content(doc) log.debug('Converting XML to HTML...') - ss = open(P('templates/fb2.xsl'), 'rb').read() + with open(P('templates/fb2.xsl'), 'rb') as f: + ss = f.read().decode('utf-8') ss = ss.replace("__FB_NS__", fb_ns) if options.no_inline_fb2_toc: log('Disabling generation of inline FB2 TOC') @@ -124,8 +125,10 @@ class FB2Input(InputFormatPlugin): src = img.get('src') img.set('src', self.binary_map.get(src, src)) index = transform.tostring(result) - open(u'index.xhtml', 'wb').write(index) - open(u'inline-styles.css', 'wb').write(css) + with open(u'index.xhtml', 'wb') as f: + f.write(index.encode('utf-8')) + with open(u'inline-styles.css', 'wb') as f: + f.write(css.encode('utf-8')) stream.seek(0) mi = get_metadata(stream, 'fb2') if not mi.title: