diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-05-03 16:48:13 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-05-03 16:48:13 +0000 |
commit | 01a255add1f54eb81a34687a341c1e6373c6e542 (patch) | |
tree | df6ed6e557310d0733fef7bd2595a18f75a86e94 /Lib/io.py | |
parent | 2f49f4eb70531de1e3a48708fe5aae0858738b68 (diff) | |
download | cpython-git-01a255add1f54eb81a34687a341c1e6373c6e542.tar.gz |
Merged revisions 80720 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r80720 | antoine.pitrou | 2010-05-03 18:25:33 +0200 (lun., 03 mai 2010) | 5 lines
Issue #7865: The close() method of :mod:`io` objects should not swallow
exceptions raised by the implicit flush(). Also ensure that calling
close() several times is supported. Patch by Pascal Chambon.
........
Diffstat (limited to 'Lib/io.py')
-rw-r--r-- | Lib/io.py | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -368,6 +368,9 @@ class IOBase(object): This is not implemented for read-only and non-blocking streams. """ + if self.__closed: + raise ValueError("flush of closed file") + #self._checkClosed() # XXX Should this return the number of bytes written??? __closed = False @@ -378,10 +381,7 @@ class IOBase(object): This method has no effect if the file is already closed. """ if not self.__closed: - try: - self.flush() - except IOError: - pass # If flush() fails, just give up + self.flush() self.__closed = True def __del__(self): @@ -751,10 +751,7 @@ class _BufferedIOMixin(BufferedIOBase): def close(self): if not self.closed: - try: - self.flush() - except IOError: - pass # If flush() fails, just give up + self.flush() self.raw.close() ### Inquiries ### @@ -1087,6 +1084,8 @@ class BufferedWriter(_BufferedIOMixin): return self.raw.truncate(pos) def flush(self): + if self.closed: + raise ValueError("flush of closed file") with self._write_lock: self._flush_unlocked() @@ -1472,11 +1471,9 @@ class TextIOWrapper(TextIOBase): self._telling = self._seekable def close(self): - try: + if not self.closed: self.flush() - except: - pass # If flush() fails, just give up - self.buffer.close() + self.buffer.close() @property def closed(self): |