mirror of
https://github.com/python/cpython.git
synced 2025-07-19 09:15:34 +00:00
make 'c' only accept bytes and 'C' only unicode #5499
This commit is contained in:
parent
605b9d9fe8
commit
7fe9853596
4 changed files with 15 additions and 14 deletions
|
@ -776,24 +776,18 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
|
|||
char *p = va_arg(*p_va, char *);
|
||||
if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
|
||||
*p = PyBytes_AS_STRING(arg)[0];
|
||||
else if (PyUnicode_Check(arg) &&
|
||||
PyUnicode_GET_SIZE(arg) == 1 &&
|
||||
PyUnicode_AS_UNICODE(arg)[0] < 256)
|
||||
*p = (char)PyUnicode_AS_UNICODE(arg)[0];
|
||||
else
|
||||
return converterr("char < 256", arg, msgbuf, bufsize);
|
||||
return converterr("a byte string of length 1", arg, msgbuf, bufsize);
|
||||
break;
|
||||
}
|
||||
|
||||
case 'C': {/* unicode char */
|
||||
int *p = va_arg(*p_va, int *);
|
||||
if (PyBytes_Check(arg) && PyBytes_Size(arg) == 1)
|
||||
*p = PyBytes_AS_STRING(arg)[0];
|
||||
else if (PyUnicode_Check(arg) &&
|
||||
PyUnicode_GET_SIZE(arg) == 1)
|
||||
if (PyUnicode_Check(arg) &&
|
||||
PyUnicode_GET_SIZE(arg) == 1)
|
||||
*p = PyUnicode_AS_UNICODE(arg)[0];
|
||||
else
|
||||
return converterr("char", arg, msgbuf, bufsize);
|
||||
return converterr("a unicode character", arg, msgbuf, bufsize);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue