summaryrefslogtreecommitdiffstats
path: root/Lib/_pyio.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2014-02-02 22:37:29 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2014-02-02 22:37:29 (GMT)
commitc06634acfcea82004373c03bd5059b02f18934fc (patch)
treea04d7e7798de91485551999a6545abb671639cdf /Lib/_pyio.py
parent1964d5bdf77fd009c7eca4527b666362d136505b (diff)
downloadcpython-c06634acfcea82004373c03bd5059b02f18934fc.zip
cpython-c06634acfcea82004373c03bd5059b02f18934fc.tar.gz
cpython-c06634acfcea82004373c03bd5059b02f18934fc.tar.bz2
Issue #20435: Fix _pyio.StringIO.getvalue() to take into account newline translation settings.
Diffstat (limited to 'Lib/_pyio.py')
-rw-r--r--Lib/_pyio.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/Lib/_pyio.py b/Lib/_pyio.py
index 0986ed2..1495994 100644
--- a/Lib/_pyio.py
+++ b/Lib/_pyio.py
@@ -1997,7 +1997,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,