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
a1b49013
Commit
a1b49013
authored
Mar 31, 2009
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix TextIOWrapper.read() when the buffer is not readable #5628
parent
d2ee64d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
0 deletions
+15
-0
Lib/_pyio.py
Lib/_pyio.py
+1
-0
Lib/test/test_io.py
Lib/test/test_io.py
+7
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/_textio.c
Modules/_textio.c
+5
-0
No files found.
Lib/_pyio.py
View file @
a1b49013
...
...
@@ -1696,6 +1696,7 @@ class TextIOWrapper(TextIOBase):
return
cookie
def
read
(
self
,
n
=
None
):
self
.
_checkReadable
()
if
n
is
None
:
n
=
-
1
decoder
=
self
.
_decoder
or
self
.
_get_decoder
()
...
...
Lib/test/test_io.py
View file @
a1b49013
...
...
@@ -1754,6 +1754,13 @@ class TextIOWrapperTest(unittest.TestCase):
self
.
assertEquals
(
f
.
read
(),
data
*
2
)
self
.
assertEquals
(
buf
.
getvalue
(),
(
data
*
2
).
encode
(
encoding
))
def
test_unreadable
(
self
):
class
UnReadable
(
self
.
BytesIO
):
def
readable
(
self
):
return
False
txt
=
self
.
TextIOWrapper
(
UnReadable
())
self
.
assertRaises
(
IOError
,
txt
.
read
)
def
test_read_one_by_one
(
self
):
txt
=
self
.
TextIOWrapper
(
self
.
BytesIO
(
b"AA
\
r
\
n
BB"
))
reads
=
""
...
...
Misc/NEWS
View file @
a1b49013
...
...
@@ -53,6 +53,8 @@ Core and Builtins
Library
-------
- Issue #5628: Fix io.TextIOWrapper.read() with a unreadable buffer.
- Issue #5619: Multiprocessing children disobey the debug flag and causes
popups on windows buildbots. Patch applied to work around this issue.
...
...
Modules/_textio.c
View file @
a1b49013
...
...
@@ -1348,6 +1348,11 @@ TextIOWrapper_read(PyTextIOWrapperObject *self, PyObject *args)
CHECK_CLOSED
(
self
);
if
(
self
->
decoder
==
NULL
)
{
PyErr_SetString
(
PyExc_IOError
,
"not readable"
);
return
NULL
;
}
if
(
_TextIOWrapper_writeflush
(
self
)
<
0
)
return
NULL
;
...
...
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