diff options
author | Guido van Rossum <guido@python.org> | 2007-05-23 21:24:35 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-05-23 21:24:35 (GMT) |
commit | e3d1d41184175f3e77c9ae1132f6d35a1117a6c3 (patch) | |
tree | 7eaf94e1f3a42efbd645447fd324b2be98daaeb3 /Modules/datetimemodule.c | |
parent | 1be7e3f2ec91a811e76972c3c7a986795f7dadbd (diff) | |
download | cpython-e3d1d41184175f3e77c9ae1132f6d35a1117a6c3.zip cpython-e3d1d41184175f3e77c9ae1132f6d35a1117a6c3.tar.gz cpython-e3d1d41184175f3e77c9ae1132f6d35a1117a6c3.tar.bz2 |
Fix datetime and its test.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r-- | Modules/datetimemodule.c | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c index f31b44c..5190175 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -927,7 +927,8 @@ call_dst(PyObject *tzinfo, PyObject *tzinfoarg, int *none) /* Call tzinfo.tzname(tzinfoarg), and return the result. tzinfo must be * an instance of the tzinfo class or None. If tzinfo isn't None, and * tzname() doesn't return None or a string, TypeError is raised and this - * returns NULL. + * returns NULL. If the result is a string, we ensure it is a Unicode + * string. */ static PyObject * call_tzname(PyObject *tzinfo, PyObject *tzinfoarg) @@ -945,12 +946,19 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg) else result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg); - if (result != NULL && result != Py_None && ! PyString_Check(result)) { - PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must " - "return None or a string, not '%s'", - result->ob_type->tp_name); - Py_DECREF(result); - result = NULL; + if (result != NULL && result != Py_None) { + if (!PyString_Check(result) && !PyUnicode_Check(result)) { + PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must " + "return None or a string, not '%s'", + result->ob_type->tp_name); + Py_DECREF(result); + result = NULL; + } + else if (!PyUnicode_Check(result)) { + PyObject *temp = PyUnicode_FromObject(result); + Py_DECREF(result); + result = temp; + } } return result; } @@ -1241,7 +1249,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, temp = call_tzname(tzinfo, tzinfoarg); if (temp == NULL) goto Done; if (temp != Py_None) { - assert(PyString_Check(temp)); + assert(PyUnicode_Check(temp)); /* Since the tzname is getting * stuffed into the format, we * have to double any % signs @@ -1255,6 +1263,11 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, Py_DECREF(temp); if (Zreplacement == NULL) goto Done; + if (PyUnicode_Check(Zreplacement)) { + Zreplacement = _PyUnicode_AsDefaultEncodedString(Zreplacement, NULL); + if (Zreplacement == NULL) + goto Done; + } if (!PyString_Check(Zreplacement)) { PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string"); goto Done; |