[issue5456] io.StringIO's universal newlines support is broken in 3.0.1

2009-03-08 Thread Erick Tryzelaar

New submission from Erick Tryzelaar :

Python version 3.0.1's io.StringIO has a bug when trying to use 
universal newlines on the mac. It's fixed in 3.1a1 though. Here's the 
exception:

>>> io.StringIO('hello there\r\nlela\r\n', newline=None).readlines()
Traceback (most recent call last):
  File "", line 1, in 
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.0/lib/python3
.0/io.py", line 536, in readlines
return list(self)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.0/lib/python3
.0/io.py", line 523, in __next__
line = self.readline()
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.0/lib/python3
.0/io.py", line 2110, in readline
more_line = self.read(self._CHUNK_SIZE)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.0/lib/python3
.0/io.py", line 2007, in read
res = self._decode_newlines(self._read(n), True)
  File 
"/opt/local/Library/Frameworks/Python.framework/Versions/3.0/lib/python3
.0/io.py", line 1953, in _decode_newlines
return output
UnboundLocalError: local variable 'output' referenced before assignment


The broken code is this:

if self._readtranslate:
if crlf:
output = input.replace("\r\n", "\n")
if cr:
output = input.replace("\r", "\n")
else:
output = input

It appears to fix the problem if we do this:

output = input
if self._readtranslate:
if crlf:
output = output.replace("\r\n", "\n")
if cr:
output = output.replace("\r", "\n")

--
components: Library (Lib)
message_count: 1.0
messages: 83352
nosy: erickt
nosy_count: 1.0
severity: normal
status: open
title: io.StringIO's universal newlines support is broken in 3.0.1
type: behavior
versions: Python 3.0

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5456] io.StringIO's universal newlines support is broken in 3.0.1

2009-03-09 Thread Benjamin Peterson

Benjamin Peterson  added the comment:

Thanks, fixed in r70285.

--
message_count: 1.0 -> 2.0
nosy: +benjamin.peterson
nosy_count: 1.0 -> 2.0
resolution:  -> fixed
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com