imp_load_module(): correct and comment the sense of the test for '+'

in the mode (it's forbidden).
This commit is contained in:
Guido van Rossum 2002-05-30 17:33:07 +00:00
parent 4ae6faed9f
commit 5e2c5fa1bd
1 changed files with 7 additions and 2 deletions

View File

@ -2408,11 +2408,16 @@ imp_load_module(PyObject *self, PyObject *args)
&name, &fob, &pathname, &name, &fob, &pathname,
&suffix, &mode, &type)) &suffix, &mode, &type))
return NULL; return NULL;
if (*mode && if (*mode) {
!(*mode == 'r' || *mode == 'U' || strchr(mode, '+'))) { /* Mode must start with 'r' or 'U' and must not contain '+'.
Implicit in this test is the assumption that the mode
may contain other modifiers like 'b' or 't'. */
if (!(*mode == 'r' || *mode == 'U') || strchr(mode, '+')) {
PyErr_Format(PyExc_ValueError, PyErr_Format(PyExc_ValueError,
"invalid file open mode %.200s", mode); "invalid file open mode %.200s", mode);
return NULL; return NULL;
}
} }
if (fob == Py_None) if (fob == Py_None)
fp = NULL; fp = NULL;