Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(370)

Unified Diff: Lib/_pyio.py

Issue 20435: Discrepancy between io.StringIO and _pyio.StringIO with univeral newlines
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Lib/test/test_memoryio.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/_pyio.py Wed Jan 29 11:45:31 2014 +0200
+++ b/Lib/_pyio.py Wed Jan 29 12:16:31 2014 +0200
@@ -2050,7 +2050,14 @@
"""
def __init__(self, initial_value="", newline="\n"):
- super(StringIO, self).__init__(BytesIO(),
+ if initial_value is not None:
+ if not isinstance(initial_value, str):
+ raise TypeError("initial_value must be str or None, not {0}"
+ .format(type(initial_value).__name__))
+ initial_value = initial_value.encode('utf-8', 'surrogatepass')
+ else:
+ initial_value = b''
+ super(StringIO, self).__init__(BytesIO(initial_value),
encoding="utf-8",
errors="surrogatepass",
newline=newline)
@@ -2058,12 +2065,6 @@
# C version, even under Windows.
if newline is None:
self._writetranslate = False
- if initial_value is not None:
- if not isinstance(initial_value, str):
- raise TypeError("initial_value must be str or None, not {0}"
- .format(type(initial_value).__name__))
- self.write(initial_value)
- self.seek(0)
def getvalue(self):
self.flush()
« no previous file with comments | « no previous file | Lib/test/test_memoryio.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+