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 "<stdin>", line 1, in <module>
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")
|