diff --git a/src/calibre/ebooks/snb/input.py b/src/calibre/ebooks/snb/input.py index 8343d44301..659ca79619 100755 --- a/src/calibre/ebooks/snb/input.py +++ b/src/calibre/ebooks/snb/input.py @@ -74,17 +74,18 @@ class SNBInput(InputFormatPlugin): chapterSrc = ch.get('src') fname = 'ch_%d.htm' % i data = snbFile.GetFileStream('snbc/' + chapterSrc) - if data != None: - snbc = etree.fromstring(data) - outputFile = open(os.path.join(tdir, fname), 'wb') - lines = [] - for line in snbc.find('.//body'): - if line.tag == 'text': - lines.append(u'

%s

' % html_encode(line.text)) - elif line.tag == 'img': - lines.append(u'

' % html_encode(line.text)) - outputFile.write((HTML_TEMPLATE % (chapterName, u'\n'.join(lines))).encode('utf-8', 'replace')) - outputFile.close() + if data == None: + continue + snbc = etree.fromstring(data) + outputFile = open(os.path.join(tdir, fname), 'wb') + lines = [] + for line in snbc.find('.//body'): + if line.tag == 'text': + lines.append(u'

%s

' % html_encode(line.text)) + elif line.tag == 'img': + lines.append(u'

' % html_encode(line.text)) + outputFile.write((HTML_TEMPLATE % (chapterName, u'\n'.join(lines))).encode('utf-8', 'replace')) + outputFile.close() oeb.toc.add(ch.text, fname) id, href = oeb.manifest.generate(id='html', href=ascii_filename(fname))