[New-bugs-announce] [issue12215] TextIOWrapper: issues with interlaced read-write
STINNER Victor
report at bugs.python.org
Mon May 30 14:38:04 CEST 2011
New submission from STINNER Victor <victor.stinner at haypocalc.com>:
The following code fails on an assertion error (Python exception for _pyio, C assertion for io):
------------------
with io.BytesIO(b'abcd') as raw:
with _pyio.TextIOWrapper(raw, encoding='ascii') as f:
f.read(1)
f.write('2')
f.tell()
------------------
I found this assertion while testing interlaced read-write on TextIOWrapper:
------------------
with io.BytesIO(b'abcd') as raw:
with _pyio.TextIOWrapper(raw, encoding='ascii') as f:
f.write("1")
# read() must call writer.flush()
assertEqual(f.read(1), 'b')
# write() must rewind the raw stream
f.write('2')
assertEqual(f.read(), 'd')
f.flush()
assertEqual(raw.getvalue(), b'1b2d')
with io.BytesIO(b'abc') as raw:
with _pyio.TextIOWrapper(raw, encoding='ascii') as f:
self.assertEqual(f.read(1), b'a')
# write() must undo reader readahead
f.write(b"2")
assertEqual(f.read(1), b'c')
f.flush()
assertEqual(raw.getvalue(), b'a2c')
------------------
These tests fails on "read, write, read" path: write() breaks TextIOWrapper internal state if a read() occured just before. Note that _pyio.TextIOWrapper.write() contains the following comment...
# XXX What if we were just reading?
See also the issue #12213 for BufferedRandom and BufferedRWPair.
----------
components: IO
messages: 137260
nosy: haypo, pitrou
priority: normal
severity: normal
status: open
title: TextIOWrapper: issues with interlaced read-write
versions: Python 3.3
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12215>
_______________________________________
More information about the New-bugs-announce
mailing list