[Python-3000-checkins] r56044 - in python/branches/py3k-struni: Lib/test/test_datetime.py Modules/datetimemodule.c Python/getargs.c Python/modsupport.c
walter.doerwald
python-3000-checkins at python.org
Wed Jun 20 13:02:47 CEST 2007
Author: walter.doerwald
Date: Wed Jun 20 13:02:38 2007
New Revision: 56044
Modified:
python/branches/py3k-struni/Lib/test/test_datetime.py
python/branches/py3k-struni/Modules/datetimemodule.c
python/branches/py3k-struni/Python/getargs.c
python/branches/py3k-struni/Python/modsupport.c
Log:
Change %c format specifier for PyArg_ParseTuple() so that it accepts
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.
Modified: python/branches/py3k-struni/Lib/test/test_datetime.py
==============================================================================
--- python/branches/py3k-struni/Lib/test/test_datetime.py (original)
+++ python/branches/py3k-struni/Lib/test/test_datetime.py Wed Jun 20 13:02:38 2007
@@ -2749,6 +2749,7 @@
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):
Modified: python/branches/py3k-struni/Modules/datetimemodule.c
==============================================================================
--- python/branches/py3k-struni/Modules/datetimemodule.c (original)
+++ python/branches/py3k-struni/Modules/datetimemodule.c Wed Jun 20 13:02:38 2007
@@ -4027,7 +4027,7 @@
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;
Modified: python/branches/py3k-struni/Python/getargs.c
==============================================================================
--- python/branches/py3k-struni/Python/getargs.c (original)
+++ python/branches/py3k-struni/Python/getargs.c Wed Jun 20 13:02:38 2007
@@ -761,15 +761,14 @@
#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;
}
Modified: python/branches/py3k-struni/Python/modsupport.c
==============================================================================
--- python/branches/py3k-struni/Python/modsupport.c (original)
+++ python/branches/py3k-struni/Python/modsupport.c Wed Jun 20 13:02:38 2007
@@ -385,9 +385,22 @@
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':
More information about the Python-3000-checkins
mailing list