[Python-checkins] cpython (3.1): Fix resource warning found manually

eric.araujo python-checkins at python.org
Wed Apr 27 16:37:45 CEST 2011


http://hg.python.org/cpython/rev/316d792bf75b
changeset:   69600:316d792bf75b
branch:      3.1
user:        Éric Araujo <merwok at netwok.org>
date:        Sun Apr 17 14:27:07 2011 +0200
summary:
  Fix resource warning found manually

files:
  Lib/distutils/command/sdist.py |  23 ++++++++++++---------
  1 files changed, 13 insertions(+), 10 deletions(-)


diff --git a/Lib/distutils/command/sdist.py b/Lib/distutils/command/sdist.py
--- a/Lib/distutils/command/sdist.py
+++ b/Lib/distutils/command/sdist.py
@@ -294,17 +294,20 @@
                             join_lines=1, lstrip_ws=1, rstrip_ws=1,
                             collapse_join=1)
 
-        while True:
-            line = template.readline()
-            if line is None:            # end of file
-                break
+        try:
+            while True:
+                line = template.readline()
+                if line is None:            # end of file
+                    break
 
-            try:
-                self.filelist.process_template_line(line)
-            except DistutilsTemplateError as msg:
-                self.warn("%s, line %d: %s" % (template.filename,
-                                               template.current_line,
-                                               msg))
+                try:
+                    self.filelist.process_template_line(line)
+                except DistutilsTemplateError as msg:
+                    self.warn("%s, line %d: %s" % (template.filename,
+                                                   template.current_line,
+                                                   msg))
+        finally:
+            template.close()
 
     def prune_file_list(self):
         """Prune off branches that might slip into the file list as created

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list