diff options
author | Brett Cannon <brett@python.org> | 2011-01-28 13:53:34 -0800 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2011-01-28 13:53:34 -0800 |
commit | 70ee44fb25cb310dee527ef696369d3f01ea64d8 (patch) | |
tree | 1798983b21c06a1ef925b1ce06cd75cac28f1d32 /coverage/html.py | |
parent | d9d71888f36367da112fe867416d3127f3cb7da7 (diff) | |
download | python-coveragepy-git-70ee44fb25cb310dee527ef696369d3f01ea64d8.tar.gz |
Properly close files.
Diffstat (limited to 'coverage/html.py')
-rw-r--r-- | coverage/html.py | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/coverage/html.py b/coverage/html.py index 76e28907..b68cc936 100644 --- a/coverage/html.py +++ b/coverage/html.py @@ -18,7 +18,11 @@ def data_filename(fname): def data(fname): """Return the contents of a data file of ours.""" - return open(data_filename(fname)).read() + data_file = open(data_filename(fname)) + try: + return data_file.read() + finally: + data_file.close() class HtmlReporter(Reporter): @@ -68,8 +72,11 @@ class HtmlReporter(Reporter): def html_file(self, cu, analysis): """Generate an HTML file for one source file.""" - - source = cu.source_file().read() + source_file = cu.source_file() + try: + source = source_file.read() + finally: + source_file.close() nums = analysis.numbers |