diff options
author | Georg Brandl <georg@python.org> | 2007-03-15 07:41:30 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-03-15 07:41:30 (GMT) |
commit | ab1f4674ad14eb1430489a458c7654aa1ac9c51e (patch) | |
tree | e994d0bc8d6ffaf75413114ac7c0e5ba610b5c4e /Lib/wave.py | |
parent | 8784bae65d9eb3066cd23b4b8cfa336dde5714b0 (diff) | |
download | cpython-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.py | 14 |
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 |