Message335132
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. |
|
Date |
User |
Action |
Args |
2019-02-09 13:36:26 | steverpalmer | set | recipients:
+ steverpalmer |
2019-02-09 13:36:22 | steverpalmer | set | messageid: <1549719382.2.0.923720230511.issue35950@roundup.psfhosted.org> |
2019-02-09 13:36:22 | steverpalmer | link | issue35950 messages |
2019-02-09 13:36:21 | steverpalmer | create | |
|