From 72626e069c727e3349c7bfdb32fb5eae04cc9945 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 17 Jul 2013 16:44:06 -0400 Subject: [PATCH] Fix the 'unqualified exec' mess (reported by Bogdan Opanchuk) --- pytools/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pytools/__init__.py b/pytools/__init__.py index 50b4f7c..5c2828e 100644 --- a/pytools/__init__.py +++ b/pytools/__init__.py @@ -1237,6 +1237,14 @@ def word_wrap(text, width, wrap_using="\n"): # {{{ command line interfaces ------------------------------------------------- +def _exec_arg(arg, execenv): + import os + if os.access(arg, os.F_OK): + exec(compile(open(arg, "r"), arg, 'exec'), execenv) + else: + exec(compile(arg, "", 'exec'), execenv) + + class CPyUserInterface(object): class Parameters(Record): pass @@ -1285,12 +1293,8 @@ class CPyUserInterface(object): execenv = self.variables.copy() execenv.update(self.constants) - import os for arg in argv[1:]: - if os.access(arg, os.F_OK): - exec(compile(open(arg, "r"), arg, 'exec'), execenv) - else: - exec(compile(arg, "", 'exec'), execenv) + _exec_arg(arg, execenv) # check if the user set invalid keys for added_key in ( -- GitLab