diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index f5beba375d..b1d760ea2d 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -977,6 +977,8 @@ def create_oebbook(log, path_or_stream, opts, input_plugin, reader=None, from calibre.ebooks.oeb.base import OEBBook html_preprocessor = HTMLPreProcessor(input_plugin.preprocess_html, opts.preprocess_html, opts) + if not encoding: + encoding = None oeb = OEBBook(log, html_preprocessor, pretty_print=opts.pretty_print, input_encoding=encoding) if not populate: diff --git a/src/calibre/ebooks/html/input.py b/src/calibre/ebooks/html/input.py index 6f875ae803..1f07f4ca41 100644 --- a/src/calibre/ebooks/html/input.py +++ b/src/calibre/ebooks/html/input.py @@ -119,7 +119,7 @@ class HTMLFile(object): self.is_binary = level > 0 and not bool(self.HTML_PAT.search(src[:4096])) if not self.is_binary: - if encoding is None: + if not encoding: encoding = xml_to_unicode(src[:4096], verbose=verbose)[-1] self.encoding = encoding else: diff --git a/src/calibre/ebooks/mobi/reader.py b/src/calibre/ebooks/mobi/reader.py index 14e3ed11c3..57f32e7131 100644 --- a/src/calibre/ebooks/mobi/reader.py +++ b/src/calibre/ebooks/mobi/reader.py @@ -139,7 +139,7 @@ class BookHeader(object): 65001: 'utf-8', }[self.codepage] except (IndexError, KeyError): - self.codec = 'cp1252' if user_encoding is None else user_encoding + self.codec = 'cp1252' if not user_encoding else user_encoding log.warn('Unknown codepage %d. Assuming %s' % (self.codepage, self.codec)) if ident == 'TEXTREAD' or self.length < 0xE4 or 0xE8 < self.length \ diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index c015868992..e11f6b45be 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1892,7 +1892,7 @@ class OEBBook(object): return fix_data(data.decode(bom_enc)) except UnicodeDecodeError: pass - if self.input_encoding is not None: + if self.input_encoding: try: return fix_data(data.decode(self.input_encoding, 'replace')) except UnicodeDecodeError: diff --git a/src/calibre/ebooks/pdb/palmdoc/reader.py b/src/calibre/ebooks/pdb/palmdoc/reader.py index 945e31559a..439492ba0c 100644 --- a/src/calibre/ebooks/pdb/palmdoc/reader.py +++ b/src/calibre/ebooks/pdb/palmdoc/reader.py @@ -65,9 +65,9 @@ class Reader(FormatReader): from calibre.customize.ui import plugin_for_input_format txt_plugin = plugin_for_input_format('txt') - for option in txt_plugin.options: - if not hasattr(self.options, option.option.name): - setattr(self.options, option.name, option.recommended_value) + for opt in txt_plugin.options: + if not hasattr(self.options, opt.option.name): + setattr(self.options, opt.option.name, opt.recommended_value) stream.seek(0) return txt_plugin.convert(stream, self.options, 'txt', self.log, {}) diff --git a/src/calibre/ebooks/pdb/pdf/reader.py b/src/calibre/ebooks/pdb/pdf/reader.py index 30b0c4c57c..2a9636b083 100644 --- a/src/calibre/ebooks/pdb/pdf/reader.py +++ b/src/calibre/ebooks/pdb/pdf/reader.py @@ -31,9 +31,9 @@ class Reader(FormatReader): from calibre.customize.ui import plugin_for_input_format pdf_plugin = plugin_for_input_format('pdf') - for option in pdf_plugin.options: - if not hasattr(self.options, option.option.name): - setattr(self.options, option.name, option.recommended_value) + for opt in pdf_plugin.options: + if not hasattr(self.options, opt.option.name): + setattr(self.options, opt.option.name, opt.recommended_value) pdf.seek(0) return pdf_plugin.convert(pdf, self.options, 'pdf', self.log, {}) diff --git a/src/calibre/ebooks/pdb/ztxt/reader.py b/src/calibre/ebooks/pdb/ztxt/reader.py index 6e7f5dd923..cff7382754 100644 --- a/src/calibre/ebooks/pdb/ztxt/reader.py +++ b/src/calibre/ebooks/pdb/ztxt/reader.py @@ -83,9 +83,9 @@ class Reader(FormatReader): from calibre.customize.ui import plugin_for_input_format txt_plugin = plugin_for_input_format('txt') - for option in txt_plugin.options: - if not hasattr(self.options, option.option.name): - setattr(self.options, option.name, option.recommended_value) + for opt in txt_plugin.options: + if not hasattr(self.options, opt.option.name): + setattr(self.options, opt.option.name, opt.recommended_value) stream.seek(0) return txt_plugin.convert(stream, self.options, 'txt', self.log, {}) diff --git a/src/calibre/ebooks/tcr/input.py b/src/calibre/ebooks/tcr/input.py index aac72da7a8..4d15fd0923 100644 --- a/src/calibre/ebooks/tcr/input.py +++ b/src/calibre/ebooks/tcr/input.py @@ -26,9 +26,9 @@ class TCRInput(InputFormatPlugin): from calibre.customize.ui import plugin_for_input_format txt_plugin = plugin_for_input_format('txt') - for option in txt_plugin.options: - if not hasattr(options, option.option.name): - setattr(options, option.name, option.recommended_value) + for opt in txt_plugin.options: + if not hasattr(self.options, opt.option.name): + setattr(self.options, opt.option.name, opt.recommended_value) stream.seek(0) return txt_plugin.convert(stream, options, diff --git a/src/calibre/gui2/convert/__init__.py b/src/calibre/gui2/convert/__init__.py index ea7a24510a..925fecd693 100644 --- a/src/calibre/gui2/convert/__init__.py +++ b/src/calibre/gui2/convert/__init__.py @@ -146,6 +146,8 @@ class Widget(QWidget): codecs.lookup(ans) except: ans = '' + if not ans: + ans = None return ans elif isinstance(g, QComboBox): return unicode(g.currentText())