[Python-checkins] cpython: Close file handles in a timely manner in packaging.database (#12504).

eric.araujo python-checkins at python.org
Fri Jul 8 17:22:39 CEST 2011


http://hg.python.org/cpython/rev/2b9a0a091566
changeset:   71254:2b9a0a091566
user:        Éric Araujo <merwok at netwok.org>
date:        Fri Jul 08 17:22:19 2011 +0200
summary:
  Close file handles in a timely manner in packaging.database (#12504).

This fixes a bug with the remove (uninstall) feature on Windows.  Patch
by Thomas Holmes.

files:
  Lib/packaging/database.py             |  12 +++++++-----
  Lib/packaging/tests/test_uninstall.py |   2 --
  Misc/ACKS                             |   1 +
  Misc/NEWS                             |   3 +++
  4 files changed, 11 insertions(+), 7 deletions(-)


diff --git a/Lib/packaging/database.py b/Lib/packaging/database.py
--- a/Lib/packaging/database.py
+++ b/Lib/packaging/database.py
@@ -158,17 +158,18 @@
             self.name, self.version, self.path)
 
     def _get_records(self, local=False):
+        results = []
         with self.get_distinfo_file('RECORD') as record:
             record_reader = csv.reader(record, delimiter=',',
                                        lineterminator='\n')
-            # XXX needs an explaining comment
             for row in record_reader:
-                path, checksum, size = (row[:] +
-                                        [None for i in range(len(row), 3)])
+                missing = [None for i in range(len(row), 3)]
+                path, checksum, size = row + missing
                 if local:
                     path = path.replace('/', os.sep)
                     path = os.path.join(sys.prefix, path)
-                yield path, checksum, size
+                results.append((path, checksum, size))
+        return results
 
     def get_resource_path(self, relative_path):
         with self.get_distinfo_file('RESOURCES') as resources_file:
@@ -197,7 +198,8 @@
         :type local: boolean
         :returns: iterator of (path, md5, size)
         """
-        return self._get_records(local)
+        for result in self._get_records(local):
+            yield result
 
     def uses(self, path):
         """
diff --git a/Lib/packaging/tests/test_uninstall.py b/Lib/packaging/tests/test_uninstall.py
--- a/Lib/packaging/tests/test_uninstall.py
+++ b/Lib/packaging/tests/test_uninstall.py
@@ -93,7 +93,6 @@
         self.assertRaises(PackagingError, remove, 'Foo',
                           paths=[self.root_dir])
 
-    @unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
     def test_uninstall(self):
         dist, install_lib = self.install_dist()
         self.assertIsFile(install_lib, 'foo', '__init__.py')
@@ -103,7 +102,6 @@
         self.assertIsNotFile(install_lib, 'foo', 'sub', '__init__.py')
         self.assertIsNotFile(install_lib, 'Foo-0.1.dist-info', 'RECORD')
 
-    @unittest.skipIf(sys.platform == 'win32', 'deactivated for now')
     def test_remove_issue(self):
         # makes sure if there are OSErrors (like permission denied)
         # remove() stops and display a clean error
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -419,6 +419,7 @@
 Gerrit Holl
 Shane Holloway
 Rune Holm
+Thomas Holmes
 Philip Homburg
 Naofumi Honda
 Jeffrey Honig
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -219,6 +219,9 @@
 Library
 -------
 
+- Issue #12504: Close file handles in a timely manner in packaging.database.
+  This fixes a bug with the remove (uninstall) feature on Windows.
+
 - Issues #12169 and #10510: Factor out code used by various packaging commands
   to make HTTP POST requests, and make sure it uses CRLF.
 

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


More information about the Python-checkins mailing list