diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-31 21:27:04 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-10-31 21:27:04 (GMT) |
commit | 4d98489da32689b3d8cc8eb4a3c1402fa3bb8f20 (patch) | |
tree | 7079f72c300225d676bfa7c34b6abac1b10574c5 /Lib/sunau.py | |
parent | b373799e0583f368a1736ac9cd02011ba6725bcb (diff) | |
download | cpython-4d98489da32689b3d8cc8eb4a3c1402fa3bb8f20.zip cpython-4d98489da32689b3d8cc8eb4a3c1402fa3bb8f20.tar.gz cpython-4d98489da32689b3d8cc8eb4a3c1402fa3bb8f20.tar.bz2 |
Issue #10265: Close file objects explicitly in sunau. Patch by Brian Brazil.
Diffstat (limited to 'Lib/sunau.py')
-rw-r--r-- | Lib/sunau.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/sunau.py b/Lib/sunau.py index 5f50e8f..6775a53 100644 --- a/Lib/sunau.py +++ b/Lib/sunau.py @@ -154,6 +154,9 @@ class Au_read: if type(f) == type(''): import builtins f = builtins.open(f, 'rb') + self._opened = True + else: + self._opened = False self.initfp(f) def __del__(self): @@ -275,6 +278,8 @@ class Au_read: self._soundpos = pos def close(self): + if self._opened and self._file: + self._file.close() self._file = None class Au_write: @@ -283,11 +288,15 @@ class Au_write: if type(f) == type(''): import builtins f = builtins.open(f, 'wb') + self._opened = True + else: + self._opened = False self.initfp(f) def __del__(self): if self._file: self.close() + self._file = None def initfp(self, file): self._file = file @@ -401,6 +410,8 @@ class Au_write: self._datalength != self._datawritten: self._patchheader() self._file.flush() + if self._opened and self._file: + self._file.close() self._file = None # |