diff options
author | Brett Cannon <brett@python.org> | 2011-01-28 13:53:20 -0800 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2011-01-28 13:53:20 -0800 |
commit | d9d71888f36367da112fe867416d3127f3cb7da7 (patch) | |
tree | 4dc79f4bb924a721ef2ddbabc545494bebd6025b /coverage/execfile.py | |
parent | b7b424bd7773b66e92474b184379723607b1a4ff (diff) | |
download | python-coveragepy-git-d9d71888f36367da112fe867416d3127f3cb7da7.tar.gz |
Open source files with the proper encoding.
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index 333163f8..8fbf63b8 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -38,10 +38,15 @@ def run_python_file(filename, args): try: # Open the source file. try: - source = open(filename, 'rU').read() + source_file = open(filename, 'rU') except IOError: raise NoSource("No file to run: %r" % filename) + try: + source = source_file.read() + finally: + source_file.close() + # We have the source. `compile` still needs the last line to be clean, # so make sure it is, then compile a code object from it. if source[-1] != '\n': |