python3: use exec() instead of execfile()

This commit is contained in:
Eli Schwartz 2019-03-21 13:10:56 -04:00
parent c68a5c8ab1
commit 9ecadb9c13
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
4 changed files with 9 additions and 4 deletions

View File

@ -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):

View File

@ -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'))

View File

@ -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',

View File

@ -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()