diff options
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 dd5a47a..81a7141 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 |