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

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'