]> granicus.if.org Git - python/commitdiff
Change %c format specifier for PyArg_ParseTuple() so that it accepts
authorWalter Dörwald <walter@livinglogic.de>
Wed, 20 Jun 2007 11:02:38 +0000 (11:02 +0000)
committerWalter Dörwald <walter@livinglogic.de>
Wed, 20 Jun 2007 11:02:38 +0000 (11:02 +0000)
a unicode character (an int * must be passed as the argument).

Change %c format specifier for Py_BuildValue() so that it outputs
a unicode object.

Fix datetime.datetime.isoformat(), so that it works if sep is
a unicode character > U+00FF.

Lib/test/test_datetime.py
Modules/datetimemodule.c
Python/getargs.c
Python/modsupport.c

index 89c126fec1c53a69954c052fdb598f5f135c51ed..b827658579fcae906c43bc6bec34d829f3dac95c 100644 (file)
@@ -2749,6 +2749,7 @@ class TestDateTimeTZ(TestDateTime, TZInfoBase, unittest.TestCase):
                 self.assertEqual(iso, datestr + 'T' + tailstr)
                 self.assertEqual(iso, d.isoformat('T'))
                 self.assertEqual(d.isoformat('k'), datestr + 'k' + tailstr)
+                self.assertEqual(d.isoformat('\u1234'), datestr + '\u1234' + tailstr)
                 self.assertEqual(str(d), datestr + ' ' + tailstr)
 
     def test_replace(self):
index d39791a8e848579c738a643733af7e8e599c831b..488d062998a44c138c30bb6917f50b0889feb4e1 100644 (file)
@@ -4027,7 +4027,7 @@ datetime_str(PyDateTime_DateTime *self)
 static PyObject *
 datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
 {
-       char sep = 'T';
+       int sep = 'T';
        static char *keywords[] = {"sep", NULL};
        char buffer[100];
        PyObject *result;
index 7b2738834a30f093a371ef8580a10eec17455c2c..1730bff1fffd06f16814d6429e2d21ed8cc1864d 100644 (file)
@@ -761,15 +761,14 @@ 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 *);
+               int *p = va_arg(*p_va, int *);
                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)
+                        PyUnicode_GET_SIZE(arg) == 1)
                        *p = PyUnicode_AS_UNICODE(arg)[0];
                else
-                       return converterr("char < 256", arg, msgbuf, bufsize);
+                       return converterr("char", arg, msgbuf, bufsize);
                break;
        }
        
index 781a331493b393597613c85cb8a33d193109374d..ba464099dd50d4b8181ada9f1069a051bed3214c 100644 (file)
@@ -385,9 +385,22 @@ do_mkvalue(const char **p_format, va_list *p_va, int flags)
 
                case 'c':
                {
-                       char p[1];
-                       p[0] = (char)va_arg(*p_va, int);
-                       return PyString_FromStringAndSize(p, 1);
+                       int i = va_arg(*p_va, int);
+                       Py_UNICODE c;
+                       if (i < 0 || i > PyUnicode_GetMax()) {
+#ifdef Py_UNICODE_WIDE
+                               PyErr_SetString(PyExc_OverflowError,
+                                               "%c arg not in range(0x110000) "
+                                               "(wide Python build)");
+#else
+                               PyErr_SetString(PyExc_OverflowError,
+                                               "%c arg not in range(0x10000) "
+                                               "(narrow Python build)");
+#endif
+                               return NULL;
+                       }
+                       c = i;
+                       return PyUnicode_FromUnicode(&c, 1);
                }
 
                case 's':