From 21376f21e7cee76761fccef6874c88c1b3f79e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Neuh=C3=A4user?= Date: Thu, 29 Apr 2010 20:34:08 +0200 Subject: [PATCH] Don't use execfile() anymore --- sphinx/config.py | 6 +++++- tests/test_quickstart.py | 12 ++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/sphinx/config.py b/sphinx/config.py index 12c2a04ba..f76d330ac 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -165,7 +165,11 @@ class Config(object): try: try: os.chdir(dirname) - execfile(config['__file__'], config) + try: + f = open(config_file, 'U') + exec f in config + finally: + f.close() except SyntaxError, err: raise ConfigError('There is a syntax error in your ' 'configuration file: ' + str(err)) diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index cb40d27cf..34c54f95a 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -85,7 +85,11 @@ def test_quickstart_defaults(tempdir): conffile = tempdir / 'conf.py' assert conffile.isfile() ns = {} - execfile(conffile, ns) + try: + f = open(conffile, 'U') + exec f in ns + finally: + f.close() assert ns['extensions'] == [] assert ns['templates_path'] == ['_templates'] assert ns['source_suffix'] == '.rst' @@ -138,7 +142,11 @@ def test_quickstart_all_answers(tempdir): conffile = tempdir / 'source' / 'conf.py' assert conffile.isfile() 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['templates_path'] == ['.templates'] assert ns['source_suffix'] == '.txt'