From d9d71888f36367da112fe867416d3127f3cb7da7 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 28 Jan 2011 13:53:20 -0800 Subject: Open source files with the proper encoding. --- coverage/execfile.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'coverage/execfile.py') 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': -- cgit v1.2.1