]> granicus.if.org Git - python/commitdiff
Issue #10265: Close file objects explicitly in sunau. Patch by Brian Brazil.
authorAntoine Pitrou <solipsis@pitrou.net>
Sun, 31 Oct 2010 21:27:04 +0000 (21:27 +0000)
committerAntoine Pitrou <solipsis@pitrou.net>
Sun, 31 Oct 2010 21:27:04 +0000 (21:27 +0000)
Lib/sunau.py
Misc/NEWS

index 5f50e8fb9c96490dc1190e3273c0ef751be2de11..6775a53cf73e0e29ae5bc6ac7398e9e51823e65c 100644 (file)
@@ -154,6 +154,9 @@ class Au_read:
         if type(f) == type(''):
             import builtins
             f = builtins.open(f, 'rb')
+            self._opened = True
+        else:
+            self._opened = False
         self.initfp(f)
 
     def __del__(self):
@@ -275,6 +278,8 @@ class Au_read:
         self._soundpos = pos
 
     def close(self):
+        if self._opened and self._file:
+            self._file.close()
         self._file = None
 
 class Au_write:
@@ -283,11 +288,15 @@ class Au_write:
         if type(f) == type(''):
             import builtins
             f = builtins.open(f, 'wb')
+            self._opened = True
+        else:
+            self._opened = False
         self.initfp(f)
 
     def __del__(self):
         if self._file:
             self.close()
+        self._file = None
 
     def initfp(self, file):
         self._file = file
@@ -401,6 +410,8 @@ class Au_write:
                   self._datalength != self._datawritten:
             self._patchheader()
         self._file.flush()
+        if self._opened and self._file:
+            self._file.close()
         self._file = None
 
     #
index abb3ebc3f2ade1fe954a5b4e456a7a032c5b7c5b..5097b95a96f24ee44bef664d997ec4394c8f9d42 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -59,6 +59,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #10265: Close file objects explicitly in sunau.  Patch by Brian Brazil.
+
 - Issue #10266: uu.decode didn't close in_file explicitly when it was given
   as a filename.  Patch by Brian Brazil.