classification
Title: StringIO can duplicate newlines in universal newlines mode
Type: behavior Stage: needs patch
Components: 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, jaraco, pitrou
Priority: normal Keywords:

Created on 2009-02-14 22:36 by pitrou, last changed 2009-05-27 20:02 by jaraco. This issue is now closed.

Messages (7)
msg82132 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-02-14 22:36
This one is a bit strange:

>>> f = io.StringIO("a\r\nb\r\n", newline=None)
>>> f.read()
'a\nb\n'
>>> f = io.StringIO("a\r\nb\r\n", newline=None)
>>> f.read(6)
'a\nb\n'
>>> f = io.StringIO("a\r\nb\r\n", newline=None)
>>> f.read(5)
'a\n\nb\n'
msg83143 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-03-04 21:38
This is fixed by the io-c branch merge. (r70152)
msg87599 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2009-05-12 01:14
Although this was fixed for 3.1, it appears not to be fixed for Python
2.6 or 2.7.

PS C:\Users\jaraco> python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:40:02) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> io.StringIO('foo\r\nbar\r\n', newline=None).read()
u'foo\n\nbar\n\n'

Note that this behavior is slightly different from what pitrou reported.

If this cannot be fixed in 2.6, the documentation should at least
reflect that it doesn't work until a later version.
msg87603 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-05-12 03:22
The bug shouldn't affect 2.6 and 2.7 unless you backported the now
obsolete _stringio module from 3.0.

I tested 2.6 and 2.7 and as expected I didn't see the bug:

Python 2.6.2+ (release26-maint:72576, May 11 2009, 23:16:48) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> io.StringIO('foo\r\nbar\r\n', newline=None).read()
u'foo\nbar\n'
msg87620 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2009-05-12 13:07
Perhaps I was wrong about 2.7.  However, I'm using stock builds of Python 2.6.2 for Windows, both 32- and 64-bit, and I get the undesirable behavior.  Apparently the problem is platform-specific.  Should this issue go under a new ticket?
msg87657 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2009-05-12 20:00
> Should this issue go under a new ticket?

Yes, it would be preferable as the issue is probably not specific to
io.StringIO. Also, make sure that you include the result of this test-case:

open("testnl.txt", "wb").write("foo\r\nbar\r\n")
open("testnl.txt", "rU").read()
msg88439 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2009-05-27 20:02
I've filed the Windows issue as http://bugs.python.org/issue6127
History
Date User Action Args
2009-05-27 20:02:25jaracosetmessages: + msg88439
2009-05-12 20:00:52alexandre.vassalottisetmessages: + msg87657
2009-05-12 13:07:42jaracosetmessages: + msg87620
2009-05-12 03:22:49alexandre.vassalottisetmessages: + msg87603
2009-05-12 01:14:18jaracosetnosy: + jaraco
messages: + msg87599
2009-03-04 21:38:49benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg83143
nosy: + benjamin.peterson
2009-02-14 22:36:17pitroucreate