diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2019-01-15 12:34:48 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-15 12:34:48 (GMT) |
commit | 1462234baf7398a6b00c0f51905e26caa17d3c60 (patch) | |
tree | 54cc4334d690454b1a33be480f62bfa3b790a84e /Modules | |
parent | 77b80c956f39df34722bd8646cf5b83d149832c4 (diff) | |
download | cpython-1462234baf7398a6b00c0f51905e26caa17d3c60.zip cpython-1462234baf7398a6b00c0f51905e26caa17d3c60.tar.gz cpython-1462234baf7398a6b00c0f51905e26caa17d3c60.tar.bz2 |
[2.7] bpo-8765: Deprecate writing unicode to binary streams in Py3k mode. (GH-11127)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/bufferedio.c | 7 | ||||
-rw-r--r-- | Modules/_io/fileio.c | 10 |
2 files changed, 16 insertions, 1 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 5bef746..b8c98a4 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -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"); diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 2b40ada..ed5b918 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -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 |