Don't use execfile() anymore

This commit is contained in:
Daniel Neuhäuser 2010-04-29 20:34:08 +02:00
parent 4adbc98350
commit 21376f21e7
2 changed files with 15 additions and 3 deletions

View File

@ -165,7 +165,11 @@ class Config(object):
try: try:
try: try:
os.chdir(dirname) os.chdir(dirname)
execfile(config['__file__'], config) try:
f = open(config_file, 'U')
exec f in config
finally:
f.close()
except SyntaxError, err: except SyntaxError, err:
raise ConfigError('There is a syntax error in your ' raise ConfigError('There is a syntax error in your '
'configuration file: ' + str(err)) 'configuration file: ' + str(err))

View File

@ -85,7 +85,11 @@ def test_quickstart_defaults(tempdir):
conffile = tempdir / 'conf.py' conffile = tempdir / 'conf.py'
assert conffile.isfile() assert conffile.isfile()
ns = {} ns = {}
execfile(conffile, ns) try:
f = open(conffile, 'U')
exec f in ns
finally:
f.close()
assert ns['extensions'] == [] assert ns['extensions'] == []
assert ns['templates_path'] == ['_templates'] assert ns['templates_path'] == ['_templates']
assert ns['source_suffix'] == '.rst' assert ns['source_suffix'] == '.rst'
@ -138,7 +142,11 @@ def test_quickstart_all_answers(tempdir):
conffile = tempdir / 'source' / 'conf.py' conffile = tempdir / 'source' / 'conf.py'
assert conffile.isfile() assert conffile.isfile()
ns = {} ns = {}
execfile(conffile, ns) try:
f = open(conffile, 'U')
exec f in ns
finally:
f.close()
assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest'] assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest']
assert ns['templates_path'] == ['.templates'] assert ns['templates_path'] == ['.templates']
assert ns['source_suffix'] == '.txt' assert ns['source_suffix'] == '.txt'