[New-bugs-announce] [issue1395] py3k: duplicated line endings when using read(1)
Amaury Forgeot d'Arc
report at bugs.python.org
Tue Nov 6 01:21:36 CET 2007
New submission from Amaury Forgeot d'Arc:
When reading a Windows text file one byte at a time, \r\n get split into
two function calls, and the user receives two \n.
The following test fails (put it somewhere in test_io.py, inside
TextIOWrapperTest for example)
def testReadOneByOne(self):
txt = io.TextIOWrapper(io.BytesIO(b"AA\r\nBB"))
reads = ""
while True:
c = txt.read(1)
if not c:
break
reads += c
self.assertEquals(reads, "AA\nBB")
# AssertionError: 'AA\n\nBB' != 'AA\nBB'
Note that replacing read(1) by read(2) gives the correct result.
This problem is why test_netrc fails on Windows. It may also be the root
cause for issue 1142 (when \r\n position is just a multiple of the
_CHUNK_SIZE).
It also possible that the correction to this problem will have good
effects on test_mailbox, which uses tell() and seek() intensively.
----------
messages: 57147
nosy: amaury.forgeotdarc, gvanrossum, tiran
severity: normal
status: open
title: py3k: duplicated line endings when using read(1)
versions: Python 3.0
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1395>
__________________________________
More information about the New-bugs-announce
mailing list