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: StringIO.read(n) does not enforce requested size in newline mode
Type: behavior Stage: needs patch
Components: Library (Lib) Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, benjamin.peterson, pitrou
Priority: normal Keywords:

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