diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2010-05-03 16:58:19 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2010-05-03 16:58:19 (GMT) |
commit | faf9007d86a6ffa4a1f611fa1c3dd449f02cef56 (patch) | |
tree | fc6355eb95c041841ecd9bb6f5de931a7744e530 /Lib/_pyio.py | |
parent | 2be7ec38d117dbbfa8719ed532b6125aa15c162e (diff) | |
download | cpython-faf9007d86a6ffa4a1f611fa1c3dd449f02cef56.zip cpython-faf9007d86a6ffa4a1f611fa1c3dd449f02cef56.tar.gz cpython-faf9007d86a6ffa4a1f611fa1c3dd449f02cef56.tar.bz2 |
Merged revisions 80722 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r80722 | antoine.pitrou | 2010-05-03 18:48:20 +0200 (lun., 03 mai 2010) | 11 lines
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/_pyio.py')
-rw-r--r-- | Lib/_pyio.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py index a9ff985..ffbfda1 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -325,6 +325,7 @@ class IOBase(metaclass=abc.ABCMeta): This is not implemented for read-only and non-blocking streams. """ + self._checkClosed() # XXX Should this return the number of bytes written??? __closed = False @@ -335,10 +336,7 @@ class IOBase(metaclass=abc.ABCMeta): 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) -> None: @@ -705,14 +703,13 @@ class _BufferedIOMixin(BufferedIOBase): ### Flush and close ### def flush(self): + if self.closed: + raise ValueError("flush of closed file") self.raw.flush() def close(self): - if not self.closed and self.raw is not None: - try: - self.flush() - except IOError: - pass # If flush() fails, just give up + if self.raw is not None and not self.closed: + self.flush() self.raw.close() def detach(self): @@ -1514,11 +1511,8 @@ class TextIOWrapper(TextIOBase): self._telling = self._seekable def close(self): - if self.buffer is not None: - try: - self.flush() - except IOError: - pass # If flush() fails, just give up + if self.buffer is not None and not self.closed: + self.flush() self.buffer.close() @property |