summaryrefslogtreecommitdiff
path: root/coverage/execfile.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2009-07-08 07:18:50 -0400
committerNed Batchelder <ned@nedbatchelder.com>2009-07-08 07:18:50 -0400
commit45f101480589b553394319af4faad34aa6fe069f (patch)
tree6046955c83f6d17834720af2ec31affdd97ecfab /coverage/execfile.py
parentd284b72806323a21caba2fc85710c9c742b3fd5a (diff)
downloadpython-coveragepy-git-45f101480589b553394319af4faad34aa6fe069f.tar.gz
Builtins moved in Py 3.x
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r--coverage/execfile.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py
index 43bdc5c3..09947bcd 100644
--- a/coverage/execfile.py
+++ b/coverage/execfile.py
@@ -2,6 +2,14 @@
import imp, os, sys
+try:
+ # In Py 2.x, the builtins were in __builtin__
+ BUILTINS = sys.modules['__builtin__']
+except KeyError:
+ # In Py 3.x, they're in builtin
+ BUILTINS = sys.modules['builtin']
+
+
def run_python_file(filename, args):
"""Run a python file as if it were the main program on the command line.
@@ -15,7 +23,7 @@ def run_python_file(filename, args):
main_mod = imp.new_module('__main__')
sys.modules['__main__'] = main_mod
main_mod.__file__ = filename
- main_mod.__builtins__ = sys.modules['__builtin__']
+ main_mod.__builtins__ = BUILTINS
# Set sys.argv and the first path element properly.
old_argv = sys.argv