Marc-Andre Lemburg: support for Unicode strings; 'U' expects a Unicode

object.
This commit is contained in:
Guido van Rossum 2000-03-10 23:02:17 +00:00
parent 5aa88f097f
commit e826ef0a89
1 changed files with 23 additions and 1 deletions

View File

@ -585,7 +585,13 @@ convertsimple1(arg, p_format, p_va)
char **p = va_arg(*p_va, char **);
if (PyString_Check(arg))
*p = PyString_AsString(arg);
*p = PyString_AS_STRING(arg);
else if (PyUnicode_Check(arg)) {
arg = PyUnicode_AsUTF8String(arg);
if (arg == NULL)
return "unicode conversion error";
*p = PyString_AS_STRING(arg);
}
else
return "string";
if ((int)strlen(*p) != PyString_Size(arg))
@ -625,6 +631,12 @@ convertsimple1(arg, p_format, p_va)
*p = 0;
else if (PyString_Check(arg))
*p = PyString_AsString(arg);
else if (PyUnicode_Check(arg)) {
arg = PyUnicode_AsUTF8String(arg);
if (arg == NULL)
return "unicode conversion error";
*p = PyString_AS_STRING(arg);
}
else
return "None or string";
if (*format == '#') {
@ -652,6 +664,16 @@ convertsimple1(arg, p_format, p_va)
break;
}
case 'U': /* Unicode object */
{
PyObject **p = va_arg(*p_va, PyObject **);
if (PyUnicode_Check(arg))
*p = arg;
else
return "unicode";
break;
}
case 'O': /* object */
{
PyTypeObject *type;