summaryrefslogtreecommitdiff
path: root/coverage
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2011-01-30 11:49:52 -0500
committerNed Batchelder <ned@nedbatchelder.com>2011-01-30 11:49:52 -0500
commitadf371a94bb59e76502611adafc1fb6640608bf6 (patch)
tree9784597560b8872cf7eb7508016ac09ee5029fc4 /coverage
parent0459af8e8aa6766d5348baa7bd65b6464d3b08f4 (diff)
downloadpython-coveragepy-adf371a94bb59e76502611adafc1fb6640608bf6.tar.gz
A bunch more places where a file close should be in a finally clause.
Diffstat (limited to 'coverage')
-rw-r--r--coverage/html.py12
-rw-r--r--coverage/parser.py12
2 files changed, 16 insertions, 8 deletions
diff --git a/coverage/html.py b/coverage/html.py
index b68cc93..bf49002 100644
--- a/coverage/html.py
+++ b/coverage/html.py
@@ -145,8 +145,10 @@ class HtmlReporter(Reporter):
html_path = os.path.join(self.directory, html_filename)
html = spaceless(self.source_tmpl.render(locals()))
fhtml = open(html_path, 'w')
- fhtml.write(html)
- fhtml.close()
+ try:
+ fhtml.write(html)
+ finally:
+ fhtml.close()
# Save this file's information for the index file.
self.files.append({
@@ -166,8 +168,10 @@ class HtmlReporter(Reporter):
totals = sum([f['nums'] for f in files])
fhtml = open(os.path.join(self.directory, "index.html"), "w")
- fhtml.write(index_tmpl.render(locals()))
- fhtml.close()
+ try:
+ fhtml.write(index_tmpl.render(locals()))
+ finally:
+ fhtml.close()
# Helpers for templates and generating HTML
diff --git a/coverage/parser.py b/coverage/parser.py
index a71ac10..3dee80e 100644
--- a/coverage/parser.py
+++ b/coverage/parser.py
@@ -24,8 +24,10 @@ class CodeParser(object):
if not self.text:
try:
sourcef = open_source(self.filename)
- self.text = sourcef.read()
- sourcef.close()
+ try:
+ self.text = sourcef.read()
+ finally:
+ sourcef.close()
except IOError:
_, err, _ = sys.exc_info()
raise NoSource(
@@ -303,8 +305,10 @@ class ByteParser(object):
if not text:
assert filename, "If no code or text, need a filename"
sourcef = open(filename, 'rU')
- text = sourcef.read()
- sourcef.close()
+ try:
+ text = sourcef.read()
+ finally:
+ sourcef.close()
try:
# Python 2.3 and 2.4 don't like partial last lines, so be sure