From 25b16f89e08be50c08fcc0f29ade8172d33cb347 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Neuh=C3=A4user?= Date: Sat, 8 May 2010 22:00:15 +0200 Subject: [PATCH] Use code objects for exec statements instead of files --- sphinx/config.py | 3 ++- tests/test_quickstart.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/sphinx/config.py b/sphinx/config.py index c22a5ee74..2ec769871 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -167,9 +167,10 @@ class Config(object): os.chdir(dirname) f = open(config_file, 'U') try: - exec f in config + code = compile(f.read(), config_file, 'exec') finally: f.close() + exec code in config 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 71ca95a4d..8acff5884 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -87,9 +87,10 @@ def test_quickstart_defaults(tempdir): ns = {} f = open(conffile, 'U') try: - exec f in ns + code = compile(f.read(), conffile, 'exec') finally: f.close() + exec code in ns assert ns['extensions'] == [] assert ns['templates_path'] == ['_templates'] assert ns['source_suffix'] == '.rst' @@ -144,9 +145,10 @@ def test_quickstart_all_answers(tempdir): ns = {} f = open(conffile, 'U') try: - exec f in ns + code = compile(f.read(), conffile, 'exec') finally: f.close() + exec code in ns assert ns['extensions'] == ['sphinx.ext.autodoc', 'sphinx.ext.doctest'] assert ns['templates_path'] == ['.templates'] assert ns['source_suffix'] == '.txt'