[New-bugs-announce] [issue23099] BytesIO and StringIO values unavailable when closed
Martin Panter
report at bugs.python.org
Mon Dec 22 12:41:17 CET 2014
New submission from Martin Panter:
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
----------
components: IO
messages: 233016
nosy: vadmium
priority: normal
severity: normal
status: open
title: BytesIO and StringIO values unavailable when closed
type: behavior
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23099>
_______________________________________
More information about the New-bugs-announce
mailing list