mirror of
https://github.com/python/cpython.git
synced 2025-09-02 15:07:53 +00:00
Some changes in preparation of stricter rules about mixing str and bytes.
This commit is contained in:
parent
ddd25825c8
commit
a4b8d1de7c
2 changed files with 14 additions and 9 deletions
|
@ -403,18 +403,16 @@ source_as_string(PyObject *cmd)
|
|||
char *str;
|
||||
Py_ssize_t size;
|
||||
|
||||
if (!PyObject_CheckReadBuffer(cmd) &&
|
||||
!PyUnicode_Check(cmd)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"eval()/exec() arg 1 must be a string, bytes or code object");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (PyUnicode_Check(cmd)) {
|
||||
cmd = _PyUnicode_AsDefaultEncodedString(cmd, NULL);
|
||||
if (cmd == NULL)
|
||||
return NULL;
|
||||
}
|
||||
else if (!PyObject_CheckReadBuffer(cmd)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"eval()/exec() arg 1 must be a string, bytes or code object");
|
||||
return NULL;
|
||||
}
|
||||
if (PyObject_AsReadBuffer(cmd, (const void **)&str, &size) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue