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
1462234b
Commit
1462234b
authored
Jan 15, 2019
by
Serhiy Storchaka
Committed by
GitHub
Jan 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.7] bpo-8765: Deprecate writing unicode to binary streams in Py3k mode. (GH-11127)
parent
77b80c95
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
3 deletions
+24
-3
Lib/test/test_fileio.py
Lib/test/test_fileio.py
+6
-2
Misc/NEWS.d/next/Library/2018-12-12-09-59-41.bpo-8765.IFupT2.rst
...WS.d/next/Library/2018-12-12-09-59-41.bpo-8765.IFupT2.rst
+2
-0
Modules/_io/bufferedio.c
Modules/_io/bufferedio.c
+7
-0
Modules/_io/fileio.c
Modules/_io/fileio.c
+9
-1
No files found.
Lib/test/test_fileio.py
View file @
1462234b
...
...
@@ -12,7 +12,7 @@ from functools import wraps
from
UserList
import
UserList
from
test.test_support
import
TESTFN
,
check_warnings
,
run_unittest
,
make_bad_fd
from
test.test_support
import
py3k_bytes
as
bytes
,
cpython_only
from
test.test_support
import
py3k_bytes
as
bytes
,
cpython_only
,
check_py3k_warnings
from
test.script_helper
import
run_python
from
_io
import
FileIO
as
_FileIO
...
...
@@ -101,6 +101,10 @@ class AutoFileTests(unittest.TestCase):
self
.
assertEqual
(
self
.
f
.
readline
(
None
),
b"hi
\
n
"
)
self
.
assertEqual
(
self
.
f
.
readlines
(
None
),
[
b"bye
\
n
"
,
b"abc"
])
def
testWriteUnicode
(
self
):
with
check_py3k_warnings
():
self
.
f
.
write
(
u''
)
def
testRepr
(
self
):
self
.
assertEqual
(
repr
(
self
.
f
),
"<_io.FileIO name=%r mode='%s'>"
%
(
self
.
f
.
name
,
self
.
f
.
mode
))
...
...
@@ -210,7 +214,7 @@ class AutoFileTests(unittest.TestCase):
@
ClosedFDRaises
def
testErrnoOnClosedWrite
(
self
,
f
):
f
.
write
(
'a'
)
f
.
write
(
b
'a'
)
@
ClosedFDRaises
def
testErrnoOnClosedSeek
(
self
,
f
):
...
...
Misc/NEWS.d/next/Library/2018-12-12-09-59-41.bpo-8765.IFupT2.rst
0 → 100644
View file @
1462234b
The write() method of buffered and unbuffered binary streams in the io
module emits now a DeprecationWarning in Py3k mode for unicode argument.
Modules/_io/bufferedio.c
View file @
1462234b
...
...
@@ -1812,6 +1812,13 @@ bufferedwriter_write(buffered *self, PyObject *args)
if
(
!
PyArg_ParseTuple
(
args
,
"s*:write"
,
&
buf
))
{
return
NULL
;
}
if
(
PyUnicode_Check
(
PyTuple_GET_ITEM
(
args
,
0
))
&&
PyErr_WarnPy3k
(
"write() argument must be string or buffer, "
"not 'unicode'"
,
1
)
<
0
)
{
PyBuffer_Release
(
&
buf
);
return
NULL
;
}
if
(
IS_CLOSED
(
self
))
{
PyErr_SetString
(
PyExc_ValueError
,
"write to closed file"
);
...
...
Modules/_io/fileio.c
View file @
1462234b
...
...
@@ -716,8 +716,16 @@ fileio_write(fileio *self, PyObject *args)
if
(
!
self
->
writable
)
return
err_mode
(
"writing"
);
if
(
!
PyArg_ParseTuple
(
args
,
"s*
"
,
&
pbuf
))
if
(
!
PyArg_ParseTuple
(
args
,
"s*
:write"
,
&
pbuf
))
{
return
NULL
;
}
if
(
PyUnicode_Check
(
PyTuple_GET_ITEM
(
args
,
0
))
&&
PyErr_WarnPy3k
(
"write() argument must be string or buffer, "
"not 'unicode'"
,
1
)
<
0
)
{
PyBuffer_Release
(
&
pbuf
);
return
NULL
;
}
if
(
_PyVerify_fd
(
self
->
fd
))
{
Py_BEGIN_ALLOW_THREADS
...
...
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