mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merged revisions 72422,72425-72426 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r72422 | benjamin.peterson | 2009-05-07 07:45:38 -0400 (Thu, 07 May 2009) | 1 line actually close files instead of leaving it to the gc #5955 ........ 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. ........
This commit is contained in:
parent
0dfd954292
commit
d0a4539632
3 changed files with 24 additions and 6 deletions
12
Lib/aifc.py
12
Lib/aifc.py
|
@ -282,10 +282,11 @@ class Aifc_read:
|
||||||
self._convert = None
|
self._convert = None
|
||||||
self._markers = []
|
self._markers = []
|
||||||
self._soundpos = 0
|
self._soundpos = 0
|
||||||
self._file = Chunk(file)
|
self._file = file
|
||||||
if self._file.getname() != 'FORM':
|
chunk = Chunk(file)
|
||||||
|
if chunk.getname() != 'FORM':
|
||||||
raise Error, 'file does not start with FORM id'
|
raise Error, 'file does not start with FORM id'
|
||||||
formdata = self._file.read(4)
|
formdata = chunk.read(4)
|
||||||
if formdata == 'AIFF':
|
if formdata == 'AIFF':
|
||||||
self._aifc = 0
|
self._aifc = 0
|
||||||
elif formdata == 'AIFC':
|
elif formdata == 'AIFC':
|
||||||
|
@ -347,7 +348,7 @@ class Aifc_read:
|
||||||
if self._decomp:
|
if self._decomp:
|
||||||
self._decomp.CloseDecompressor()
|
self._decomp.CloseDecompressor()
|
||||||
self._decomp = None
|
self._decomp = None
|
||||||
self._file = None
|
self._file.close()
|
||||||
|
|
||||||
def tell(self):
|
def tell(self):
|
||||||
return self._soundpos
|
return self._soundpos
|
||||||
|
@ -732,8 +733,7 @@ class Aifc_write:
|
||||||
if self._comp:
|
if self._comp:
|
||||||
self._comp.CloseCompressor()
|
self._comp.CloseCompressor()
|
||||||
self._comp = None
|
self._comp = None
|
||||||
self._file.flush()
|
self._file.close()
|
||||||
self._file = None
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Internal methods.
|
# Internal methods.
|
||||||
|
|
|
@ -45,6 +45,21 @@ class AIFCTest(unittest.TestCase):
|
||||||
|
|
||||||
#XXX Need more tests!
|
#XXX Need more tests!
|
||||||
|
|
||||||
|
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():
|
def test_main():
|
||||||
run_unittest(AIFCTest)
|
run_unittest(AIFCTest)
|
||||||
|
|
|
@ -40,6 +40,9 @@ Core and Builtins
|
||||||
Library
|
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 #4875: On win32, ctypes.util.find_library does no longer
|
- Issue #4875: On win32, ctypes.util.find_library does no longer
|
||||||
return directories.
|
return directories.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue