Issue #20435: Fix _pyio.StringIO.getvalue() to take into account newline translation settings.

This commit is contained in:
Antoine Pitrou 2014-02-02 23:38:48 +01:00
commit 1328e9d0a0
3 changed files with 19 additions and 1 deletions

View file

@ -2067,7 +2067,13 @@ class StringIO(TextIOWrapper):
def getvalue(self):
self.flush()
return self.buffer.getvalue().decode(self._encoding, self._errors)
decoder = self._decoder or self._get_decoder()
old_state = decoder.getstate()
decoder.reset()
try:
return decoder.decode(self.buffer.getvalue(), final=True)
finally:
decoder.setstate(old_state)
def __repr__(self):
# TextIOWrapper tells the encoding in its repr. In StringIO,