summaryrefslogtreecommitdiffstats
path: root/Lib/wave.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2007-03-15 07:41:30 (GMT)
committerGeorg Brandl <georg@python.org>2007-03-15 07:41:30 (GMT)
commitab1f4674ad14eb1430489a458c7654aa1ac9c51e (patch)
treee994d0bc8d6ffaf75413114ac7c0e5ba610b5c4e /Lib/wave.py
parent8784bae65d9eb3066cd23b4b8cfa336dde5714b0 (diff)
downloadcpython-ab1f4674ad14eb1430489a458c7654aa1ac9c51e.zip
cpython-ab1f4674ad14eb1430489a458c7654aa1ac9c51e.tar.gz
cpython-ab1f4674ad14eb1430489a458c7654aa1ac9c51e.tar.bz2
Patch #1681153: the wave module now closes a file object it opened if
initialization failed.
Diffstat (limited to 'Lib/wave.py')
-rw-r--r--Lib/wave.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/wave.py b/Lib/wave.py
index 08c51ba..b993b40 100644
--- a/Lib/wave.py
+++ b/Lib/wave.py
@@ -159,7 +159,12 @@ class Wave_read:
f = __builtin__.open(f, 'rb')
self._i_opened_the_file = f
# else, assume it is an open file object already
- self.initfp(f)
+ try:
+ self.initfp(f)
+ except:
+ if self._i_opened_the_file:
+ f.close()
+ raise
def __del__(self):
self.close()
@@ -297,7 +302,12 @@ class Wave_write:
if isinstance(f, basestring):
f = __builtin__.open(f, 'wb')
self._i_opened_the_file = f
- self.initfp(f)
+ try:
+ self.initfp(f)
+ except:
+ if self._i_opened_the_file:
+ f.close()
+ raise
def initfp(self, file):
self._file = file