homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: codec.StreamReaderWriter: issues with interlaced read-write
Type: behavior Stage: resolved
Components: Library (Lib), Unicode Versions: Python 3.4, Python 3.5, Python 2.7
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, doerwalter, lemburg, vstinner
Priority: normal Keywords:

Created on 2011年07月07日 13:12 by vstinner, last changed 2022年04月11日 14:57 by admin. This issue is now closed.

Messages (3)
msg139975 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011年07月07日 13:12
The following test fails with an AssertionError('a' != 'b') on the first read.
import codecs
FILENAME = 'test'
with open(FILENAME, 'wb') as f:
 f.write('abcd'.encode('utf-8'))
with codecs.open(FILENAME, 'r+', encoding='utf-8') as f:
 f.write("1")
 pos = f.writer.tell()
 assert pos == 1, "writer pos: %s != 1" % pos
 pos = f.reader.tell()
 assert pos == 1, "reader pos: %s != 1" % pos
 pos = f.stream.tell()
 assert pos == 1, "stream pos: %s != 1" % pos
 # read() must call writer.flush()
 char = f.read(1)
 assert char == 'b', "%r != 'b'" % (char,)
 # write() must rewind the raw stream
 f.write('3')
 tail = f.read()
 assert tail == 'd', "%r != 'd'" % (tail,)
 f.flush()
 with open(FILENAME, 'rb') as f:
 assert f.read() == b'1b3d'
I suppose that readline(), readlines() and __next__() have also issues.
See also issue #12215: similar issue with io.TextIOWrapper.
msg222225 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014年07月03日 22:00
Codecs gurus FYI.
msg297128 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2017年06月28日 01:39
Sorry, I just lost track of this issue and so will just close it. Moreover, I also closed issue12215.
History
Date User Action Args
2022年04月11日 14:57:19adminsetgithub: 56722
2017年06月28日 01:39:55vstinnersetstatus: open -> closed
resolution: out of date
messages: + msg297128

stage: resolved
2014年07月03日 22:00:45BreamoreBoysetversions: + Python 3.4, Python 3.5, - Python 3.2, Python 3.3
nosy: + BreamoreBoy, lemburg, doerwalter

messages: + msg222225

type: behavior
2011年07月07日 13:12:46vstinnercreate

AltStyle によって変換されたページ (->オリジナル) /