Message233016
IOBase.close() doc says file operations raise ValueError, but it is not obvious to me that reading back the “file” buffer is a file operation.
>>> with BytesIO() as b:
... b.write(b"123")
...
3
>>> b.getvalue()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file.
Even worse, the memoryview gets corrupted on close():
>>> b = BytesIO(b"123")
>>> m = b.getbuffer()
>>> b.close()
>>> bytes(m)
b'\x98\x02>'
I also noticed that in the “io” implementation, writing to the file seems to be completely disallowed, even if it would not seem to change the size:
>>> b = BytesIO(b"123")
>>> m = b.getbuffer()
>>> b.write(b"x")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BufferError: Existing exports of data: object cannot be re-sized |
|
Date |
User |
Action |
Args |
2014-12-22 11:41:17 | martin.panter | set | recipients:
+ martin.panter |
2014-12-22 11:41:17 | martin.panter | set | messageid: <1419248477.31.0.512702147737.issue23099@psf.upfronthosting.co.za> |
2014-12-22 11:41:17 | martin.panter | link | issue23099 messages |
2014-12-22 11:41:16 | martin.panter | create | |
|