diff options
author | Walter Dörwald <walter@livinglogic.de> | 2007-05-19 21:49:49 (GMT) |
---|---|---|
committer | Walter Dörwald <walter@livinglogic.de> | 2007-05-19 21:49:49 (GMT) |
commit | 7569dfe11d51a11bfb11002d31245b889916fb11 (patch) | |
tree | 7e4cbbb7a27a366ea0cdc8eeacc05a23f649e4cd /Modules/_elementtree.c | |
parent | 94b59bb14474b6fe5a272a2c60b65f8375e827b3 (diff) | |
download | cpython-7569dfe11d51a11bfb11002d31245b889916fb11.zip cpython-7569dfe11d51a11bfb11002d31245b889916fb11.tar.gz cpython-7569dfe11d51a11bfb11002d31245b889916fb11.tar.bz2 |
Add a format specifier %R to PyUnicode_FromFormat(), which embeds
the result of a call to PyObject_Repr() into the string. This makes
it possible to simplify many repr implementations.
PyUnicode_FromFormat() uses two steps to create the final string: A first
pass through the format string determines the size of the final string and
a second pass creates the string. To avoid calling PyObject_Repr() twice
for each %R specifier, PyObject_Repr() is called during the size
calculation step and the results are stored in an array (whose size is
determined at the start by counting %R specifiers).
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 12 |
1 files changed, 1 insertions, 11 deletions
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* |