Compare and hash unicode objects like their UTF-8 representations.

Accept Unicode characters < 256 for 'c' format.
This commit is contained in:
Guido van Rossum 2007-05-04 04:17:33 +00:00
parent f15a29f975
commit 09dc34fc9c
2 changed files with 26 additions and 50 deletions

View file

@ -764,8 +764,12 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
char *p = va_arg(*p_va, char *);
if (PyString_Check(arg) && PyString_Size(arg) == 1)
*p = PyString_AS_STRING(arg)[0];
else if (PyUnicode_Check(arg) &&
PyUnicode_GET_SIZE(arg) == 1 &&
PyUnicode_AS_UNICODE(arg)[0] < 256)
*p = PyUnicode_AS_UNICODE(arg)[0];
else
return converterr("char", arg, msgbuf, bufsize);
return converterr("char < 256", arg, msgbuf, bufsize);
break;
}