Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
57839a63
Commit
57839a63
authored
Feb 02, 2014
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #20435: Fix _pyio.StringIO.getvalue() to take into account newline translation settings.
parent
6bb21c48
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
1 deletion
+19
-1
Lib/_pyio.py
Lib/_pyio.py
+7
-1
Lib/test/test_memoryio.py
Lib/test/test_memoryio.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/_pyio.py
View file @
57839a63
...
...
@@ -2060,7 +2060,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,
...
...
Lib/test/test_memoryio.py
View file @
57839a63
...
...
@@ -551,6 +551,7 @@ class TextIOTestMixin:
self
.
assertEqual
(
3
,
memio
.
write
(
"c
\
r
d"
))
memio
.
seek
(
0
)
self
.
assertEqual
(
memio
.
read
(),
"a
\
n
b
\
n
c
\
n
d"
)
self
.
assertEqual
(
memio
.
getvalue
(),
"a
\
n
b
\
n
c
\
n
d"
)
memio
=
self
.
ioclass
(
"a
\
r
\
n
b"
,
newline
=
None
)
self
.
assertEqual
(
memio
.
read
(
3
),
"a
\
n
b"
)
...
...
@@ -562,6 +563,7 @@ class TextIOTestMixin:
self
.
assertEqual
(
memio
.
read
(
4
),
"a
\
n
b
\
r
"
)
self
.
assertEqual
(
memio
.
read
(
2
),
"
\
n
c"
)
self
.
assertEqual
(
memio
.
read
(
1
),
"
\
r
"
)
self
.
assertEqual
(
memio
.
getvalue
(),
"a
\
n
b
\
r
\
n
c
\
r
d"
)
memio
=
self
.
ioclass
(
newline
=
""
)
self
.
assertEqual
(
2
,
memio
.
write
(
"a
\
n
"
))
self
.
assertEqual
(
2
,
memio
.
write
(
"b
\
r
"
))
...
...
@@ -581,6 +583,9 @@ class TextIOTestMixin:
self
.
assertEqual
(
memio
.
read
(),
"a
\
r
b
\
r
\
r
c
\
r
d"
)
memio
.
seek
(
0
)
self
.
assertEqual
(
list
(
memio
),
[
"a
\
r
"
,
"b
\
r
"
,
"
\
r
"
,
"c
\
r
"
,
"d"
])
memio
.
seek
(
0
)
self
.
assertEqual
(
memio
.
readlines
(),
[
"a
\
r
"
,
"b
\
r
"
,
"
\
r
"
,
"c
\
r
"
,
"d"
])
self
.
assertEqual
(
memio
.
getvalue
(),
"a
\
r
b
\
r
\
r
c
\
r
d"
)
def
test_newline_crlf
(
self
):
# newline="\r\n"
...
...
@@ -588,11 +593,15 @@ class TextIOTestMixin:
self
.
assertEqual
(
memio
.
read
(),
"a
\
r
\
n
b
\
r
\
r
\
n
c
\
r
d"
)
memio
.
seek
(
0
)
self
.
assertEqual
(
list
(
memio
),
[
"a
\
r
\
n
"
,
"b
\
r
\
r
\
n
"
,
"c
\
r
d"
])
memio
.
seek
(
0
)
self
.
assertEqual
(
memio
.
readlines
(),
[
"a
\
r
\
n
"
,
"b
\
r
\
r
\
n
"
,
"c
\
r
d"
])
self
.
assertEqual
(
memio
.
getvalue
(),
"a
\
r
\
n
b
\
r
\
r
\
n
c
\
r
d"
)
def
test_issue5265
(
self
):
# StringIO can duplicate newlines in universal newlines mode
memio
=
self
.
ioclass
(
"a
\
r
\
n
b
\
r
\
n
"
,
newline
=
None
)
self
.
assertEqual
(
memio
.
read
(
5
),
"a
\
n
b
\
n
"
)
self
.
assertEqual
(
memio
.
getvalue
(),
"a
\
n
b
\
n
"
)
def
test_newline_argument
(
self
):
self
.
assertRaises
(
TypeError
,
self
.
ioclass
,
newline
=
b"
\
n
"
)
...
...
Misc/NEWS
View file @
57839a63
...
...
@@ -45,6 +45,9 @@ Core and Builtins
Library
-------
-
Issue
#
20435
:
Fix
_pyio
.
StringIO
.
getvalue
()
to
take
into
account
newline
translation
settings
.
-
Issue
#
20288
:
fix
handling
of
invalid
numeric
charrefs
in
HTMLParser
.
-
Issue
#
20424
:
Python
implementation
of
io
.
StringIO
now
supports
lone
surrogates
.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment