summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorRobert Collins <rbtcollins@hp.com>2015-07-25 18:43:13 (GMT)
committerRobert Collins <rbtcollins@hp.com>2015-07-25 18:43:13 (GMT)
commitc94a1dc4c9a5d23fdb21f6928dd737a59ef3dfb2 (patch)
treeabbbf37e11a6ba307ba00eaa2cf40e27d62d09d2 /Modules/_io
parent882667203ca638ffce4238740c521c2a8320be09 (diff)
downloadcpython-c94a1dc4c9a5d23fdb21f6928dd737a59ef3dfb2.zip
cpython-c94a1dc4c9a5d23fdb21f6928dd737a59ef3dfb2.tar.gz
cpython-c94a1dc4c9a5d23fdb21f6928dd737a59ef3dfb2.tar.bz2
- Issue #2091: error correctly on open() with mode 'U' and '+'
open() accepted a 'U' mode string containing '+', but 'U' can only be used with 'r'. Patch from Jeff Balogh and John O'Connor.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/_iomodule.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c
index 528bcd4..1c2d3a0 100644
--- a/Modules/_io/_iomodule.c
+++ b/Modules/_io/_iomodule.c
@@ -248,8 +248,8 @@ _io_open_impl(PyModuleDef *module, PyObject *file, const char *mode,
_Py_IDENTIFIER(close);
if (!PyUnicode_Check(file) &&
- !PyBytes_Check(file) &&
- !PyNumber_Check(file)) {
+ !PyBytes_Check(file) &&
+ !PyNumber_Check(file)) {
PyErr_Format(PyExc_TypeError, "invalid file: %R", file);
return NULL;
}
@@ -307,9 +307,9 @@ _io_open_impl(PyModuleDef *module, PyObject *file, const char *mode,
/* Parameters validation */
if (universal) {
- if (writing || appending) {
+ if (creating || writing || appending || updating) {
PyErr_SetString(PyExc_ValueError,
- "can't use U and writing mode at once");
+ "mode U cannot be combined with x', 'w', 'a', or '+'");
return NULL;
}
if (PyErr_WarnEx(PyExc_DeprecationWarning,
@@ -437,10 +437,10 @@ _io_open_impl(PyModuleDef *module, PyObject *file, const char *mode,
/* wraps into a TextIOWrapper */
wrapper = PyObject_CallFunction((PyObject *)&PyTextIOWrapper_Type,
- "Osssi",
- buffer,
- encoding, errors, newline,
- line_buffering);
+ "Osssi",
+ buffer,
+ encoding, errors, newline,
+ line_buffering);
if (wrapper == NULL)
goto error;
result = wrapper;