diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2007-08-12 00:43:29 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2007-08-12 00:43:29 (GMT) |
commit | 016880229a369a3fb419f3eed28b6db7c342fe71 (patch) | |
tree | 9b11de5c197bc556dd515e035327673765cd4871 /Lib/doctest.py | |
parent | 41eaedd3613cebc83e6b9925499369992c7a7770 (diff) | |
download | cpython-016880229a369a3fb419f3eed28b6db7c342fe71.zip cpython-016880229a369a3fb419f3eed28b6db7c342fe71.tar.gz cpython-016880229a369a3fb419f3eed28b6db7c342fe71.tar.bz2 |
Kill execfile(), use exec() instead
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r-- | Lib/doctest.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/Lib/doctest.py b/Lib/doctest.py index 0f40818..ec51657 100644 --- a/Lib/doctest.py +++ b/Lib/doctest.py @@ -2490,7 +2490,7 @@ def debug_script(src, pm=False, globs=None): # Note that tempfile.NameTemporaryFile() cannot be used. As the # docs say, a file so created cannot be opened by name a second time - # on modern Windows boxes, and execfile() needs to open it. + # on modern Windows boxes, and exec() needs to open and read it. srcfilename = tempfile.mktemp(".py", "doctestdebug") f = open(srcfilename, 'w') f.write(src) @@ -2504,14 +2504,17 @@ def debug_script(src, pm=False, globs=None): if pm: try: - execfile(srcfilename, globs, globs) + exec(open(srcfilename).read(), globs, globs) except: print(sys.exc_info()[1]) pdb.post_mortem(sys.exc_info()[2]) else: - # Note that %r is vital here. '%s' instead can, e.g., cause - # backslashes to get treated as metacharacters on Windows. - pdb.run("execfile(%r)" % srcfilename, globs, globs) + fp = open(srcfilename) + try: + script = fp.read() + finally: + fp.close() + pdb.run("exec(%r)" % script, globs, globs) finally: os.remove(srcfilename) |