Issue 5266: StringIO.read(n) does not enforce requested size in newline mode

Created on 2009-02-14 22:50 by pitrou, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg82134 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-02-14 22:50
Or, more precisely, it returns less than the requested number of
characters because characters are counted before translating newlines:

>>> f = io.StringIO("a\r\nb\r\n", newline=None)
>>> f.read(3)
'a\n'

TextIOWrapper gets it right:

>>> g = io.TextIOWrapper(io.BytesIO(b"a\r\nb\r\n"), newline=None)
>>> g.read(3)
'a\nb'
msg83142 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-04 21:38
This is fixed by the io-c branch merge. (r70152)
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49516
2009-03-04 21:38:43benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg83142
nosy: + benjamin.peterson
2009-02-14 22:50:07pitroucreate