diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-05-18 17:15:44 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-05-18 17:15:44 (GMT) |
commit | 1ab833082738ced53318aca05901e596d5ede683 (patch) | |
tree | 0ff2b4c1fcbab3233e012f04bce801cadfd6d7f9 /Modules/datetimemodule.c | |
parent | 14176a56d3fe36388115688d0b5acae0c759c044 (diff) | |
download | cpython-1ab833082738ced53318aca05901e596d5ede683.zip cpython-1ab833082738ced53318aca05901e596d5ede683.tar.gz cpython-1ab833082738ced53318aca05901e596d5ede683.tar.bz2 |
Add functions PyUnicode_Append() and PyUnicode_AppendAndDel() that mirror
PyString_Concat() and PyString_ConcatAndDel() (the name PyUnicode_Concat()
was already taken).
Change PyObject_Repr() to always return a unicode object.
Update all repr implementations to return unicode objects.
Add a function PyObject_ReprStr8() that calls PyObject_Repr() and converts
the result to an 8bit string.
Use PyObject_ReprStr8() where using PyObject_Repr() can't be done
straightforward.
Diffstat (limited to 'Modules/datetimemodule.c')
-rw-r--r-- | Modules/datetimemodule.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c index c31d8e6..5d3c679 100644 --- a/Modules/datetimemodule.c +++ b/Modules/datetimemodule.c @@ -1044,27 +1044,27 @@ append_keyword_tzinfo(PyObject *repr, PyObject *tzinfo) { PyObject *temp; - assert(PyString_Check(repr)); + assert(PyUnicode_Check(repr)); assert(tzinfo); if (tzinfo == Py_None) return repr; /* Get rid of the trailing ')'. */ - assert(PyString_AsString(repr)[PyString_Size(repr)-1] == ')'); - temp = PyString_FromStringAndSize(PyString_AsString(repr), - PyString_Size(repr) - 1); + assert(PyUnicode_AS_UNICODE(repr)[PyUnicode_GET_SIZE(repr)-1] == ')'); + temp = PyUnicode_FromUnicode(PyUnicode_AS_UNICODE(repr), + PyUnicode_GET_SIZE(repr) - 1); Py_DECREF(repr); if (temp == NULL) return NULL; repr = temp; /* Append ", tzinfo=". */ - PyString_ConcatAndDel(&repr, PyString_FromString(", tzinfo=")); + PyUnicode_AppendAndDel(&repr, PyUnicode_FromString(", tzinfo=")); /* Append repr(tzinfo). */ - PyString_ConcatAndDel(&repr, PyObject_Repr(tzinfo)); + PyUnicode_AppendAndDel(&repr, PyObject_Repr(tzinfo)); /* Add a closing paren. */ - PyString_ConcatAndDel(&repr, PyString_FromString(")")); + PyUnicode_AppendAndDel(&repr, PyUnicode_FromString(")")); return repr; } @@ -1972,18 +1972,18 @@ static PyObject * delta_repr(PyDateTime_Delta *self) { if (GET_TD_MICROSECONDS(self) != 0) - return PyString_FromFormat("%s(%d, %d, %d)", + return PyUnicode_FromFormat("%s(%d, %d, %d)", self->ob_type->tp_name, GET_TD_DAYS(self), GET_TD_SECONDS(self), GET_TD_MICROSECONDS(self)); if (GET_TD_SECONDS(self) != 0) - return PyString_FromFormat("%s(%d, %d)", + return PyUnicode_FromFormat("%s(%d, %d)", self->ob_type->tp_name, GET_TD_DAYS(self), GET_TD_SECONDS(self)); - return PyString_FromFormat("%s(%d)", + return PyUnicode_FromFormat("%s(%d)", self->ob_type->tp_name, GET_TD_DAYS(self)); } @@ -2410,7 +2410,7 @@ date_repr(PyDateTime_Date *self) type_name, GET_YEAR(self), GET_MONTH(self), GET_DAY(self)); - return PyString_FromString(buffer); + return PyUnicode_FromString(buffer); } static PyObject * @@ -3131,7 +3131,7 @@ time_repr(PyDateTime_Time *self) else PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d)", type_name, h, m); - result = PyString_FromString(buffer); + result = PyUnicode_FromString(buffer); if (result != NULL && HASTZINFO(self)) result = append_keyword_tzinfo(result, self->tzinfo); return result; @@ -4043,7 +4043,7 @@ datetime_repr(PyDateTime_DateTime *self) GET_YEAR(self), GET_MONTH(self), GET_DAY(self), DATE_GET_HOUR(self), DATE_GET_MINUTE(self)); } - baserepr = PyString_FromString(buffer); + baserepr = PyUnicode_FromString(buffer); if (baserepr == NULL || ! HASTZINFO(self)) return baserepr; return append_keyword_tzinfo(baserepr, self->tzinfo); |