From 65c0ca944b86fe8f0cc898a1e2b0b5ad0c176cd3 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 19 May 2019 14:56:07 -0400 Subject: [PATCH] py3: make pml input work Opening a file in binary mode in python3 returns a BufferedReader which does not have an encoding attribute. Assume in this case it is functionally equivalent to None. I'm not sure when pml_stream.encoding will ever equal anything, since even on python2 the attribute exists but is None when opening files in binary mode... which we explicitly do. So I'm not sure why this ever checks the existing encoding. Possibly when the input plugin is given a file opened in text mode, not raw mode? in that case, it may be wrong to always decode it when reading. --- src/calibre/ebooks/conversion/plugins/pml_input.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/conversion/plugins/pml_input.py b/src/calibre/ebooks/conversion/plugins/pml_input.py index 3388bdefd3..8bdb773358 100644 --- a/src/calibre/ebooks/conversion/plugins/pml_input.py +++ b/src/calibre/ebooks/conversion/plugins/pml_input.py @@ -41,7 +41,9 @@ class PMLInput(InputFormatPlugin): else: html_stream = html_path - ienc = pml_stream.encoding if pml_stream.encoding else 'cp1252' + ienc = getattr(pml_stream, 'encoding', None) + if ienc is None: + ienc = 'cp1252' if self.options.input_encoding: ienc = self.options.input_encoding