]> granicus.if.org Git - python/commitdiff
Revert r56044 (which changed the %c format specifier to accept a
authorWalter Dörwald <walter@livinglogic.de>
Sun, 1 Jul 2007 21:58:22 +0000 (21:58 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Sun, 1 Jul 2007 21:58:22 +0000 (21:58 +0000)
unicode char into an int variable) and add %C which does this.

Modules/arraymodule.c
Modules/datetimemodule.c
Python/getargs.c
Python/modsupport.c

index 6c9038af3df193155834d43fcd0bf01882ee221d..253907757af259be78054faf88b833d2b9a9dcf6 100644 (file)
@@ -1785,7 +1785,7 @@ array_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
        if (type == &Arraytype && !_PyArg_NoKeywords("array.array()", kwds))
                return NULL;
 
-       if (!PyArg_ParseTuple(args, "c|O:array", &c, &initial))
+       if (!PyArg_ParseTuple(args, "C|O:array", &c, &initial))
                return NULL;
 
        if (!(initial == NULL || PyList_Check(initial)
index 488d062998a44c138c30bb6917f50b0889feb4e1..61f9ab7d0ab39729d2f1d9e408b8e52a605a6d5d 100644 (file)
@@ -4033,7 +4033,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
        PyObject *result;
        int us = DATE_GET_MICROSECOND(self);
 
-       if (!PyArg_ParseTupleAndKeywords(args, kw, "|c:isoformat", keywords, &sep))
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "|C:isoformat", keywords, &sep))
                return NULL;
        if (us)
                result = PyUnicode_FromFormat("%04d-%02d-%02d%c%02d:%02d:%02d.%06d",
index 1730bff1fffd06f16814d6429e2d21ed8cc1864d..ce1fef72650c0cc1093ee81328241d6ec777fe16 100644 (file)
@@ -761,6 +761,19 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
 #endif /* WITHOUT_COMPLEX */
        
        case 'c': {/* char */
+               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 < 256", arg, msgbuf, bufsize);
+               break;
+       }
+       
+       case 'C': {/* unicode char */
                int *p = va_arg(*p_va, int *);
                if (PyString_Check(arg) && PyString_Size(arg) == 1)
                        *p = PyString_AS_STRING(arg)[0];
index ba464099dd50d4b8181ada9f1069a051bed3214c..330da5fe800005f7a50687164d7482944b48320a 100644 (file)
@@ -384,6 +384,12 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
 #endif /* WITHOUT_COMPLEX */
 
                case 'c':
+               {
+                       char p[1];
+                       p[0] = (char)va_arg(*p_va, int);
+                       return PyString_FromStringAndSize(p, 1);
+               }
+               case 'C':
                {
                        int i = va_arg(*p_va, int);
                        Py_UNICODE c;