[New-bugs-announce] [issue5266] StringIO.read(n) does not enforce requested size in newline mode

Antoine Pitrou report at bugs.python.org
Sat Feb 14 23:50:08 CET 2009


New submission from Antoine Pitrou <pitrou at free.fr>:

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'

----------
components: Library (Lib)
messages: 82134
nosy: alexandre.vassalotti, pitrou
priority: normal
severity: normal
stage: needs patch
status: open
title: StringIO.read(n) does not enforce requested size in newline mode
type: behavior
versions: Python 2.6, Python 2.7, Python 3.0, Python 3.1

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5266>
_______________________________________


More information about the New-bugs-announce mailing list