From 991c913bb2ab264eb6afbdf20493ca43eb3323b2 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 27 May 2019 12:09:33 -0400 Subject: [PATCH] use bytestring directly for file template Don't bother storing it as a u'' string, then doing nothing with it other than encoding it to write it to a file. Also touch up use of open() to close the file via a contextmanager. --- src/calibre/ebooks/conversion/plumber.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calibre/ebooks/conversion/plumber.py b/src/calibre/ebooks/conversion/plumber.py index 6b1920c0d4..a37a143750 100644 --- a/src/calibre/ebooks/conversion/plumber.py +++ b/src/calibre/ebooks/conversion/plumber.py @@ -20,7 +20,7 @@ from calibre import (extract, walk, isbytestring, filesystem_encoding, from calibre.constants import __version__ from polyglot.builtins import unicode_type, string_or_bytes, map -DEBUG_README=u''' +DEBUG_README=b''' This debug directory contains snapshots of the e-book as it passes through the various stages of conversion. The stages are: @@ -1061,8 +1061,8 @@ OptionRecommendation(name='search_replace', self.opts.debug_pipeline = os.path.abspath(self.opts.debug_pipeline) if not os.path.exists(self.opts.debug_pipeline): os.makedirs(self.opts.debug_pipeline) - open(os.path.join(self.opts.debug_pipeline, 'README.txt'), - 'wb').write(DEBUG_README.encode('utf-8')) + with open(os.path.join(self.opts.debug_pipeline, 'README.txt'), 'wb') as f: + f.write(DEBUG_README) for x in ('input', 'parsed', 'structure', 'processed'): x = os.path.join(self.opts.debug_pipeline, x) if os.path.exists(x):