]> granicus.if.org Git - python/commitdiff
Marc-Andre Lemburg: support for Unicode strings; 'U' expects a Unicode
authorGuido van Rossum <guido@python.org>
Fri, 10 Mar 2000 23:02:17 +0000 (23:02 +0000)
committerGuido van Rossum <guido@python.org>
Fri, 10 Mar 2000 23:02:17 +0000 (23:02 +0000)
object.

Python/getargs.c

index 2d9e2b712bbc0f52e82f716d8d026d4f06f15c05..4617d0515e4fcae5381989e0ce721357b3933445 100644 (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;