From 16943d29886df91300121fced970134d0c2b9806 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 30 Jan 2011 11:49:52 -0500 Subject: A bunch more places where a file close should be in a finally clause. --- coverage/parser.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'coverage/parser.py') diff --git a/coverage/parser.py b/coverage/parser.py index a71ac102..3dee80eb 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 -- cgit v1.2.1