summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2000-10-09 23:43:55 (GMT)
committerTim Peters <tim.peters@gmail.com>2000-10-09 23:43:55 (GMT)
commitcfc4178e843f5f2b0f190bacd222c0f72ab91e53 (patch)
tree02fc024fbff8112772407f9ba1b9b7f2ea9ef0a9 /Lib
parente8d2f5589bdbe8988c97b2f8bb265f1aca2b4193 (diff)
downloadcpython-cfc4178e843f5f2b0f190bacd222c0f72ab91e53.zip
cpython-cfc4178e843f5f2b0f190bacd222c0f72ab91e53.tar.gz
cpython-cfc4178e843f5f2b0f190bacd222c0f72ab91e53.tar.bz2
When the classes in wave.py opened files themselves, their .close() methods
didn't bother to close the files. This caused the new test_wave test to fail under Windows, as Windows won't let you delete a file that's open. Fixed that by ensuring the wave read & write classes' .close() and __del__ methods close files that were opened by their constructors.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/wave.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/Lib/wave.py b/Lib/wave.py
index 49e070f..e9a1629 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -152,11 +152,15 @@ class Wave_read:
raise Error, 'fmt chunk and/or data chunk missing'
def __init__(self, f):
+ self._i_opened_the_file = None
if type(f) == type(''):
f = __builtin__.open(f, 'rb')
+ self._i_opened_the_file = f
# else, assume it is an open file object already
self.initfp(f)
+ def __del__(self):
+ self.close()
#
# User visible methods.
#
@@ -168,6 +172,9 @@ class Wave_read:
self._soundpos = 0
def close(self):
+ if self._i_opened_the_file:
+ self._i_opened_the_file.close()
+ self._i_opened_the_file = None
self._file = None
def tell(self):
@@ -284,8 +291,10 @@ class Wave_write:
"""
def __init__(self, f):
+ self._i_opened_the_file = None
if type(f) == type(''):
f = __builtin__.open(f, 'wb')
+ self._i_opened_the_file = f
self.initfp(f)
def initfp(self, file):
@@ -300,8 +309,7 @@ class Wave_write:
self._datalength = 0
def __del__(self):
- if self._file:
- self.close()
+ self.close()
#
# User visible methods.
@@ -413,11 +421,15 @@ class Wave_write:
self._patchheader()
def close(self):
- self._ensure_header_written(0)
- if self._datalength != self._datawritten:
- self._patchheader()
- self._file.flush()
- self._file = None
+ if self._file:
+ self._ensure_header_written(0)
+ if self._datalength != self._datawritten:
+ self._patchheader()
+ self._file.flush()
+ self._file = None
+ if self._i_opened_the_file:
+ self._i_opened_the_file.close()
+ self._i_opened_the_file = None
#
# Internal methods.