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.

Author erickt
Recipients erickt
Date 2009-03-09.03:05:29
SpamBayes Score 4.191092e-14
Marked as misclassified No
Message-id <1236567931.99.0.98085182563.issue5456@psf.upfronthosting.co.za>
In-reply-to
Content
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")
History
Date User Action Args
2009-03-09 03:05:32ericktsetrecipients: + erickt
2009-03-09 03:05:31ericktsetmessageid: <1236567931.99.0.98085182563.issue5456@psf.upfronthosting.co.za>
2009-03-09 03:05:30ericktlinkissue5456 messages
2009-03-09 03:05:29ericktcreate