mirror of
https://github.com/python/cpython.git
synced 2024-11-26 03:14:27 +08:00
Fix datetime and its test.
This commit is contained in:
parent
1be7e3f2ec
commit
e3d1d41184
@ -1098,7 +1098,8 @@ class TestDate(HarmlessMixedComparison, unittest.TestCase):
|
|||||||
# This shouldn't blow up because of the month byte alone. If
|
# This shouldn't blow up because of the month byte alone. If
|
||||||
# the implementation changes to do more-careful checking, it may
|
# the implementation changes to do more-careful checking, it may
|
||||||
# blow up because other fields are insane.
|
# blow up because other fields are insane.
|
||||||
self.theclass(base[:2] + chr(ord_byte) + base[3:])
|
# XXX Maybe this will have to become bytes?
|
||||||
|
self.theclass(str8(base[:2] + chr(ord_byte) + base[3:]))
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
# datetime tests
|
# datetime tests
|
||||||
|
@ -927,7 +927,8 @@ call_dst(PyObject *tzinfo, PyObject *tzinfoarg, int *none)
|
|||||||
/* Call tzinfo.tzname(tzinfoarg), and return the result. tzinfo must be
|
/* 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
|
* 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
|
* 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 *
|
static PyObject *
|
||||||
call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
|
call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
|
||||||
@ -945,12 +946,19 @@ call_tzname(PyObject *tzinfo, PyObject *tzinfoarg)
|
|||||||
else
|
else
|
||||||
result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg);
|
result = PyObject_CallMethod(tzinfo, "tzname", "O", tzinfoarg);
|
||||||
|
|
||||||
if (result != NULL && result != Py_None && ! PyString_Check(result)) {
|
if (result != NULL && result != Py_None) {
|
||||||
PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
|
if (!PyString_Check(result) && !PyUnicode_Check(result)) {
|
||||||
"return None or a string, not '%s'",
|
PyErr_Format(PyExc_TypeError, "tzinfo.tzname() must "
|
||||||
result->ob_type->tp_name);
|
"return None or a string, not '%s'",
|
||||||
Py_DECREF(result);
|
result->ob_type->tp_name);
|
||||||
result = NULL;
|
Py_DECREF(result);
|
||||||
|
result = NULL;
|
||||||
|
}
|
||||||
|
else if (!PyUnicode_Check(result)) {
|
||||||
|
PyObject *temp = PyUnicode_FromObject(result);
|
||||||
|
Py_DECREF(result);
|
||||||
|
result = temp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -1241,7 +1249,7 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
|
|||||||
temp = call_tzname(tzinfo, tzinfoarg);
|
temp = call_tzname(tzinfo, tzinfoarg);
|
||||||
if (temp == NULL) goto Done;
|
if (temp == NULL) goto Done;
|
||||||
if (temp != Py_None) {
|
if (temp != Py_None) {
|
||||||
assert(PyString_Check(temp));
|
assert(PyUnicode_Check(temp));
|
||||||
/* Since the tzname is getting
|
/* Since the tzname is getting
|
||||||
* stuffed into the format, we
|
* stuffed into the format, we
|
||||||
* have to double any % signs
|
* have to double any % signs
|
||||||
@ -1255,6 +1263,11 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
|
|||||||
Py_DECREF(temp);
|
Py_DECREF(temp);
|
||||||
if (Zreplacement == NULL)
|
if (Zreplacement == NULL)
|
||||||
goto Done;
|
goto Done;
|
||||||
|
if (PyUnicode_Check(Zreplacement)) {
|
||||||
|
Zreplacement = _PyUnicode_AsDefaultEncodedString(Zreplacement, NULL);
|
||||||
|
if (Zreplacement == NULL)
|
||||||
|
goto Done;
|
||||||
|
}
|
||||||
if (!PyString_Check(Zreplacement)) {
|
if (!PyString_Check(Zreplacement)) {
|
||||||
PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string");
|
PyErr_SetString(PyExc_TypeError, "tzname.replace() did not return a string");
|
||||||
goto Done;
|
goto Done;
|
||||||
|
Loading…
Reference in New Issue
Block a user