From a430138f93447bda6bf8efa9389ffb7474275677 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 16 Jun 2015 11:01:38 +0530 Subject: [PATCH] HTML To Zip: Ignore user specified encoding if it is invalid --- src/calibre/ebooks/html/to_zip.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/calibre/ebooks/html/to_zip.py b/src/calibre/ebooks/html/to_zip.py index 450cc09747..545432d1d9 100644 --- a/src/calibre/ebooks/html/to_zip.py +++ b/src/calibre/ebooks/html/to_zip.py @@ -26,6 +26,8 @@ every time you add an HTML file to the library.\ on_import = True def run(self, htmlfile): + import codecs + from calibre import prints from calibre.ptempfile import TemporaryDirectory from calibre.gui2.convert.gui_conversion import gui_convert from calibre.customize.conversion import OptionRecommendation @@ -38,8 +40,12 @@ every time you add an HTML file to the library.\ sc = self.site_customization.strip() enc, _, bf = sc.partition('|') if enc: - recs.append(['input_encoding', enc, - OptionRecommendation.HIGH]) + try: + codecs.lookup(enc) + except Exception: + prints('Ignoring invalid input encoding for HTML:', enc) + else: + recs.append(['input_encoding', enc, OptionRecommendation.HIGH]) if bf == 'bf': recs.append(['breadth_first', True, OptionRecommendation.HIGH]) @@ -84,8 +90,7 @@ every time you add an HTML file to the library.\ help_text = self.customization_help(gui=True) help_text = QLabel(help_text, config_dialog) help_text.setWordWrap(True) - help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse - | Qt.LinksAccessibleByKeyboard) + help_text.setTextInteractionFlags(Qt.LinksAccessibleByMouse | Qt.LinksAccessibleByKeyboard) help_text.setOpenExternalLinks(True) v.addWidget(help_text) bf = QCheckBox(_('Add linked files in breadth first order'))