summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_collectionsmodule.c26
-rw-r--r--Modules/_elementtree.c12
-rw-r--r--Modules/_tkinter.c6
-rw-r--r--Modules/arraymodule.c14
-rw-r--r--Modules/datetimemodule.c50
-rw-r--r--Modules/itertoolsmodule.c14
6 files changed, 35 insertions, 87 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 1311d4d..fc4ef15 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -627,14 +627,7 @@ deque_repr(PyObject *deque)
return NULL;
}
- result = PyUnicode_FromString("deque(");
- if (result == NULL) {
- Py_DECREF(aslist);
- Py_ReprLeave(deque);
- return NULL;
- }
- PyUnicode_AppendAndDel(&result, PyObject_Repr(aslist));
- PyUnicode_AppendAndDel(&result, PyUnicode_FromString(")"));
+ result = PyUnicode_FromFormat("deque(%R)", aslist);
Py_DECREF(aslist);
Py_ReprLeave(deque);
return result;
@@ -1208,25 +1201,18 @@ defdict_print(defdictobject *dd, FILE *fp, int flags)
static PyObject *
defdict_repr(defdictobject *dd)
{
- PyObject *defrepr;
PyObject *baserepr;
+ PyObject *def;
PyObject *result;
baserepr = PyDict_Type.tp_repr((PyObject *)dd);
if (baserepr == NULL)
return NULL;
if (dd->default_factory == NULL)
- defrepr = PyUnicode_FromString("None");
+ def = Py_None;
else
- defrepr = PyObject_Repr(dd->default_factory);
- if (defrepr == NULL) {
- Py_DECREF(baserepr);
- return NULL;
- }
- result = PyUnicode_FromString("defaultdict(");
- PyUnicode_AppendAndDel(&result, defrepr);
- PyUnicode_AppendAndDel(&result, PyUnicode_FromString(", "));
- PyUnicode_AppendAndDel(&result, baserepr);
- PyUnicode_AppendAndDel(&result, PyUnicode_FromString(")"));
+ def = dd->default_factory;
+ result = PyUnicode_FromFormat("defaultdict(%R, %U)", def, baserepr);
+ Py_DECREF(baserepr);
return result;
}
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 442ab83..2ec2332 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1118,17 +1118,7 @@ element_remove(ElementObject* self, PyObject* args)
static PyObject*
element_repr(ElementObject* self)
{
- PyObject* repr;
- char buffer[100];
-
- repr = PyUnicode_FromString("<Element ");
-
- PyUnicode_AppendAndDel(&repr, PyObject_Repr(self->tag));
-
- sprintf(buffer, " at %p>", self);
- PyUnicode_AppendAndDel(&repr, PyUnicode_FromString(buffer));
-
- return repr;
+ return PyUnicode_FromFormat("<Element %R at %p>", self->tag, self);
}
static PyObject*
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index fe568fa..790a1be 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -809,10 +809,8 @@ PyTclObject_unicode(PyTclObject *self, void *ignored)
static PyObject *
PyTclObject_repr(PyTclObject *self)
{
- char buf[50];
- PyOS_snprintf(buf, 50, "<%s object at %p>",
- self->value->typePtr->name, self->value);
- return PyUnicode_FromString(buf);
+ return PyUnicode_FromFormat("<%s object at %p>",
+ self->value->typePtr->name, self->value);
}
static int
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index d61b1ae..7349527 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1567,29 +1567,23 @@ static PyObject *
array_repr(arrayobject *a)
{
char buf[256], typecode;
- PyObject *s, *t, *v = NULL;
+ PyObject *s, *v = NULL;
Py_ssize_t len;
len = a->ob_size;
typecode = a->ob_descr->typecode;
if (len == 0) {
- PyOS_snprintf(buf, sizeof(buf), "array('%c')", typecode);
- return PyUnicode_FromString(buf);
+ return PyUnicode_FromFormat("array('%c')", typecode);
}
-
if (typecode == 'c')
v = array_tostring(a, NULL);
else if (typecode == 'u')
v = array_tounicode(a, NULL);
else
v = array_tolist(a, NULL);
- t = PyObject_Repr(v);
- Py_XDECREF(v);
- PyOS_snprintf(buf, sizeof(buf), "array('%c', ", typecode);
- s = PyUnicode_FromString(buf);
- PyUnicode_AppendAndDel(&s, t);
- PyUnicode_AppendAndDel(&s, PyUnicode_FromString(")"));
+ s = PyUnicode_FromFormat("array('%c', %R)", typecode, v);
+ Py_DECREF(v);
return s;
}
diff --git a/Modules/datetimemodule.c b/Modules/datetimemodule.c
index 5d3c679..e03148c 100644
--- a/Modules/datetimemodule.c
+++ b/Modules/datetimemodule.c
@@ -1973,19 +1973,19 @@ delta_repr(PyDateTime_Delta *self)
{
if (GET_TD_MICROSECONDS(self) != 0)
return PyUnicode_FromFormat("%s(%d, %d, %d)",
- self->ob_type->tp_name,
- GET_TD_DAYS(self),
- GET_TD_SECONDS(self),
- GET_TD_MICROSECONDS(self));
+ self->ob_type->tp_name,
+ GET_TD_DAYS(self),
+ GET_TD_SECONDS(self),
+ GET_TD_MICROSECONDS(self));
if (GET_TD_SECONDS(self) != 0)
return PyUnicode_FromFormat("%s(%d, %d)",
- self->ob_type->tp_name,
- GET_TD_DAYS(self),
- GET_TD_SECONDS(self));
+ self->ob_type->tp_name,
+ GET_TD_DAYS(self),
+ GET_TD_SECONDS(self));
return PyUnicode_FromFormat("%s(%d)",
- self->ob_type->tp_name,
- GET_TD_DAYS(self));
+ self->ob_type->tp_name,
+ GET_TD_DAYS(self));
}
static PyObject *
@@ -2402,15 +2402,9 @@ date_subtract(PyObject *left, PyObject *right)
static PyObject *
date_repr(PyDateTime_Date *self)
{
- char buffer[1028];
- const char *type_name;
-
- type_name = self->ob_type->tp_name;
- PyOS_snprintf(buffer, sizeof(buffer), "%s(%d, %d, %d)",
- type_name,
- GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
-
- return PyUnicode_FromString(buffer);
+ return PyUnicode_FromFormat("%s(%d, %d, %d)",
+ self->ob_type->tp_name,
+ GET_YEAR(self), GET_MONTH(self), GET_DAY(self));
}
static PyObject *
@@ -3114,7 +3108,6 @@ time_tzname(PyDateTime_Time *self, PyObject *unused) {
static PyObject *
time_repr(PyDateTime_Time *self)
{
- char buffer[100];
const char *type_name = self->ob_type->tp_name;
int h = TIME_GET_HOUR(self);
int m = TIME_GET_MINUTE(self);
@@ -3123,15 +3116,13 @@ time_repr(PyDateTime_Time *self)
PyObject *result = NULL;
if (us)
- PyOS_snprintf(buffer, sizeof(buffer),
- "%s(%d, %d, %d, %d)", type_name, h, m, s, us);
+ result = PyUnicode_FromFormat("%s(%d, %d, %d, %d)",
+ type_name, h, m, s, us);
else if (s)
- PyOS_snprintf(buffer, sizeof(buffer),
- "%s(%d, %d, %d)", type_name, h, m, s);
+ result = PyUnicode_FromFormat("%s(%d, %d, %d)",
+ type_name, h, m, s);
else
- PyOS_snprintf(buffer, sizeof(buffer),
- "%s(%d, %d)", type_name, h, m);
- result = PyUnicode_FromString(buffer);
+ result = PyUnicode_FromFormat("%s(%d, %d)", type_name, h, m);
if (result != NULL && HASTZINFO(self))
result = append_keyword_tzinfo(result, self->tzinfo);
return result;
@@ -4020,7 +4011,7 @@ datetime_repr(PyDateTime_DateTime *self)
PyObject *baserepr;
if (DATE_GET_MICROSECOND(self)) {
- PyOS_snprintf(buffer, sizeof(buffer),
+ baserepr = PyUnicode_FromFormat(
"%s(%d, %d, %d, %d, %d, %d, %d)",
type_name,
GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
@@ -4029,7 +4020,7 @@ datetime_repr(PyDateTime_DateTime *self)
DATE_GET_MICROSECOND(self));
}
else if (DATE_GET_SECOND(self)) {
- PyOS_snprintf(buffer, sizeof(buffer),
+ baserepr = PyUnicode_FromFormat(
"%s(%d, %d, %d, %d, %d, %d)",
type_name,
GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
@@ -4037,13 +4028,12 @@ datetime_repr(PyDateTime_DateTime *self)
DATE_GET_SECOND(self));
}
else {
- PyOS_snprintf(buffer, sizeof(buffer),
+ baserepr = PyUnicode_FromFormat(
"%s(%d, %d, %d, %d, %d)",
type_name,
GET_YEAR(self), GET_MONTH(self), GET_DAY(self),
DATE_GET_HOUR(self), DATE_GET_MINUTE(self));
}
- baserepr = PyUnicode_FromString(buffer);
if (baserepr == NULL || ! HASTZINFO(self))
return baserepr;
return append_keyword_tzinfo(baserepr, self->tzinfo);
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index c3f198e..2685ca4 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2389,20 +2389,10 @@ repeat_next(repeatobject *ro)
static PyObject *
repeat_repr(repeatobject *ro)
{
- PyObject *result, *objrepr;
-
- objrepr = PyObject_Repr(ro->element);
- if (objrepr == NULL)
- return NULL;
-
if (ro->cnt == -1)
- result = PyUnicode_FromFormat("repeat(%U)",
- objrepr);
+ return PyUnicode_FromFormat("repeat(%R)", ro->element);
else
- result = PyUnicode_FromFormat("repeat(%U, %zd)",
- objrepr, ro->cnt);
- Py_DECREF(objrepr);
- return result;
+ return PyUnicode_FromFormat("repeat(%R, %zd)", ro->element, ro->cnt);
}
static PyObject *