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 | 9681a8f11e84ae57abc7cbfba807ca847884e5a5 (patch) | |
tree | 790a52852adfaa9ad28ff71d698e1c2482ba6a11 /coverage/execfile.py | |
parent | 92ea40eb3f4d073276de0470bdee5f8c0179cd82 (diff) | |
download | python-coveragepy-9681a8f11e84ae57abc7cbfba807ca847884e5a5.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 333163f..8fbf63b 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': |