]> granicus.if.org Git - python/commitdiff
Issue5955: aifc's close method did not close the file it wrapped,
authorR. David Murray <rdmurray@bitdance.com>
Thu, 7 May 2009 16:27:02 +0000 (16:27 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 7 May 2009 16:27:02 +0000 (16:27 +0000)
now it does.  This also means getfp method now returns the real fp.

Lib/aifc.py
Lib/test/test_aifc.py

index 197e755210f652998e16ee7eca197ac217731e6d..b4123ca90fa603e40ac0437274c0fe32d7962ecc 100644 (file)
@@ -282,10 +282,11 @@ class Aifc_read:
         self._convert = None
         self._markers = []
         self._soundpos = 0
-        self._file = Chunk(file)
-        if self._file.getname() != 'FORM':
+        self._file = file
+        chunk = Chunk(file)
+        if chunk.getname() != 'FORM':
             raise Error, 'file does not start with FORM id'
-        formdata = self._file.read(4)
+        formdata = chunk.read(4)
         if formdata == 'AIFF':
             self._aifc = 0
         elif formdata == 'AIFC':
index 0aed908005ac1688ae23b79e057ff3be679b5c76..54694ea2d914e2bd8f6cf34ad7463130f1324b29 100644 (file)
@@ -91,6 +91,21 @@ class AIFCTest(unittest.TestCase):
         # XXX: this test fails, not sure if it should succeed or not
         # self.assertEqual(f.readframes(5), fout.readframes(5))
 
+    def test_close(self):
+        class Wrapfile(object):
+            def __init__(self, file):
+                self.file = open(file)
+                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)