From 9ecadb9c13033ba683c25088baab08a72664459e Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Thu, 21 Mar 2019 13:10:56 -0400 Subject: [PATCH] python3: use exec() instead of execfile() --- src/calibre/debug.py | 3 ++- src/calibre/library/catalogs/epub_mobi_builder.py | 4 +++- src/calibre/utils/ipython.py | 3 ++- src/calibre/utils/rapydscript.py | 3 ++- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/calibre/debug.py b/src/calibre/debug.py index 3b8c901377..ee2dd8fd35 100644 --- a/src/calibre/debug.py +++ b/src/calibre/debug.py @@ -248,7 +248,8 @@ def run_script(path, args): g = globals() g['__name__'] = '__main__' g['__file__'] = ef - execfile(ef, g) + with open(ef, 'rb') as f: + exec(compile(f.read(), ef, 'exec'), g) def inspect_mobi(path): diff --git a/src/calibre/library/catalogs/epub_mobi_builder.py b/src/calibre/library/catalogs/epub_mobi_builder.py index 44bbc7f166..b76bdf772f 100644 --- a/src/calibre/library/catalogs/epub_mobi_builder.py +++ b/src/calibre/library/catalogs/epub_mobi_builder.py @@ -4602,7 +4602,9 @@ class CatalogBuilder(object): """ templates = {} - execfile(P('catalog/section_list_templates.py'), templates) + ef = P('catalog/section_list_templates.py') + with open(ef, 'rb')) as f: + exec(compile(f.read(), ef, 'exec'), templates) for name, template in templates.iteritems(): if name.startswith('by_') and name.endswith('_template'): setattr(self, name, force_unicode(template, 'utf-8')) diff --git a/src/calibre/utils/ipython.py b/src/calibre/utils/ipython.py index 4377a2c172..3bfa0f8054 100644 --- a/src/calibre/utils/ipython.py +++ b/src/calibre/utils/ipython.py @@ -214,7 +214,8 @@ def ipython(user_ns=None): c = Config() user_conf = os.path.expanduser('~/.ipython/profile_default/ipython_config.py') if os.path.exists(user_conf): - execfile(user_conf, {'get_config': lambda: c}) + with open(user_conf, 'rb') as f: + exec(compile(f.read(), user_conf, 'exec'), {'get_config': lambda: c}) c.TerminalInteractiveShell.prompts_class = CustomPrompt c.InteractiveShellApp.exec_lines = [ 'from __future__ import division, absolute_import, unicode_literals, print_function', diff --git a/src/calibre/utils/rapydscript.py b/src/calibre/utils/rapydscript.py index 67db41e87e..8dde3e32e7 100644 --- a/src/calibre/utils/rapydscript.py +++ b/src/calibre/utils/rapydscript.py @@ -203,7 +203,8 @@ def compile_srv(): base = base_dir() iconf = os.path.join(base, 'imgsrc', 'srv', 'generate.py') g = {'__file__': iconf} - execfile(iconf, g) + with open(iconf, 'rb') as f: + exec(compile(f.read(), iconf, 'exec'), g) icons = g['merge']().encode('utf-8') with lopen(os.path.join(base, 'resources', 'content-server', 'reset.css'), 'rb') as f: reset = f.read()