[Python-checkins] r72425 - in python/trunk/Lib: aifc.py test/test_aifc.py
r.david.murray
python-checkins at python.org
Thu May 7 18:27:03 CEST 2009
Author: r.david.murray
Date: Thu May 7 18:27:02 2009
New Revision: 72425
Log:
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.
Modified:
python/trunk/Lib/aifc.py
python/trunk/Lib/test/test_aifc.py
Modified: python/trunk/Lib/aifc.py
==============================================================================
--- python/trunk/Lib/aifc.py (original)
+++ python/trunk/Lib/aifc.py Thu May 7 18:27:02 2009
@@ -282,10 +282,11 @@
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':
Modified: python/trunk/Lib/test/test_aifc.py
==============================================================================
--- python/trunk/Lib/test/test_aifc.py (original)
+++ python/trunk/Lib/test/test_aifc.py Thu May 7 18:27:02 2009
@@ -91,6 +91,21 @@
# 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)
More information about the Python-checkins
mailing list