]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 72423,72435 via svnmerge from
authorR. David Murray <rdmurray@bitdance.com>
Thu, 7 May 2009 18:55:11 +0000 (18:55 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 7 May 2009 18:55:11 +0000 (18:55 +0000)
svn+ssh://pythondev@svn.python.org/python/branches/py3k

................
  r72423 | benjamin.peterson | 2009-05-07 07:53:38 -0400 (Thu, 07 May 2009) | 9 lines

  Merged revisions 72422 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r72422 | benjamin.peterson | 2009-05-07 06:45:38 -0500 (Thu, 07 May 2009) | 1 line

    actually close files instead of leaving it to the gc #5955
  ........
................
  r72435 | r.david.murray | 2009-05-07 14:24:38 -0400 (Thu, 07 May 2009) | 14 lines

  Merged revisions 72425-72426 via svnmerge from
  svn+ssh://pythondev@svn.python.org/python/trunk

  ........
    r72425 | r.david.murray | 2009-05-07 12:27:02 -0400 (Thu, 07 May 2009) | 3 lines

    Issue5955: aifc's close method did not close the file it wrapped,
    now it does.  This also means getfp method now returns the real fp.
  ........
    r72426 | r.david.murray | 2009-05-07 12:29:19 -0400 (Thu, 07 May 2009) | 3 lines

    News item for Issue5955.
  ........
................

Lib/aifc.py
Lib/test/test_aifc.py
Misc/NEWS

index 36312b3c2cbe9dcd50c3f0b09c6d1f705b26821d..c307e1cf3410334a102000d808e3ea5fb08a84b5 100644 (file)
@@ -281,10 +281,11 @@ class Aifc_read:
         self._convert = None
         self._markers = []
         self._soundpos = 0
-        self._file = Chunk(file)
-        if self._file.getname() != b'FORM':
+        self._file = file
+        chunk = Chunk(file)
+        if chunk.getname() != b'FORM':
             raise Error('file does not start with FORM id')
-        formdata = self._file.read(4)
+        formdata = chunk.read(4)
         if formdata == b'AIFF':
             self._aifc = 0
         elif formdata == b'AIFC':
@@ -331,7 +332,7 @@ class Aifc_read:
         self._soundpos = 0
 
     def close(self):
-        self._file = None
+        self._file.close()
 
     def tell(self):
         return self._soundpos
@@ -690,8 +691,7 @@ class Aifc_write:
               self._datalength != self._datawritten or \
               self._marklength:
             self._patchheader()
-        self._file.flush()
-        self._file = None
+        self._file.close()
 
     #
     # Internal methods.
index a9c53a3610102542131c51835e029540918f77b4..6a7ba64d8c5762b10cfe76d08ec46a940497f086 100644 (file)
@@ -48,6 +48,21 @@ class AIFCTest(unittest.TestCase):
 
     #XXX Need more tests!
 
+    def test_close(self):
+        class Wrapfile(object):
+            def __init__(self, file):
+                self.file = open(file, 'rb')
+                self.closed = False
+            def close(self):
+                self.file.close()
+                self.closed = True
+            def __getattr__(self, attr): return getattr(self.file, attr)
+        testfile = Wrapfile(self.sndfilepath)
+        f = self.f = aifc.open(testfile)
+        self.assertEqual(testfile.closed, False)
+        f.close()
+        self.assertEqual(testfile.closed, True)
+
 
 def test_main():
     run_unittest(AIFCTest)
index 8cdc90505beb9fae594862af78bb070d296f6270..74c8959164393f84df0e20f3d3d694a6f459f40f 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -55,6 +55,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #5955: aifc's close method did not close the file it wrapped,
+  now it does.  This also means getfp method now returns the real fp.
+
 - Issue #5940: distutils.command.build_clib.check_library_list was not doing 
   the right type checkings anymore.