Author steverpalmer
Recipients steverpalmer
Date 2019-02-09.13:36:21
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1549719382.2.0.923720230511.issue35950@roundup.psfhosted.org>
In-reply-to
Content
An io.BUfferedReader object has an (inherited) writable method that returns False.  io.IOBase states in the description of the writable method that "If False, write() and truncate() will raise OSError."

However, if the BufferedReader object is constructed from a writabe io.RawIOBase object, then the truncate does not raise the exception.

>>> import io
>>> import tempfile
>>> rf = tempfile.TemporaryFile(buffering=0)
>>> rf
<_io.FileIO name=3 mode='rb+' closefd=True>
>>> bf = io.BufferedReader(rf)
>>> bf.writable()
False
>>> bf.truncate(0)
0

Looking at _pyio.py file, the truncate method in the  _BufferedIOMixin wrapper class delegates the truncation to it's raw attribute.  If the raw element permits the truncation, then it will proceed regardless of the writable state of the wrapper class.  I'd suggest that modifying the truncate method in _BufferedIOMixin to raise OSError (or Unsupported) if not self.writable() could fix this problem.
History
Date User Action Args
2019-02-09 13:36:26steverpalmersetrecipients: + steverpalmer
2019-02-09 13:36:22steverpalmersetmessageid: <1549719382.2.0.923720230511.issue35950@roundup.psfhosted.org>
2019-02-09 13:36:22steverpalmerlinkissue35950 messages
2019-02-09 13:36:21steverpalmercreate