Fix repr of tree Element on windows.

This commit is contained in:
Florent Xicluna 2010-03-11 15:55:11 +00:00
parent 3e8c189faa
commit e2e81e8fcd
2 changed files with 12 additions and 10 deletions

View File

@ -131,7 +131,7 @@ def check_element(element):
# element tree tests
def interface():
"""
r"""
Test element tree interface.
>>> element = ET.Element("tag")
@ -139,10 +139,11 @@ def interface():
>>> tree = ET.ElementTree(element)
>>> check_element(tree.getroot())
>>> element = ET.Element("tag", key="value")
>>> element = ET.Element("t\xe4g", key="value")
>>> tree = ET.ElementTree(element)
>>> repr(element) # doctest: +ELLIPSIS
"<Element 'tag' at 0x...>"
"<Element 't\\xe4g' at 0x...>"
>>> element = ET.Element("tag", key="value")
Make sure all standard element methods exist.

View File

@ -1190,15 +1190,16 @@ element_remove(ElementObject* self, PyObject* args)
static PyObject*
element_repr(ElementObject* self)
{
PyObject* repr;
char buffer[100];
repr = PyString_FromString("<Element ");
PyObject *repr, *tag;
PyString_ConcatAndDel(&repr, PyObject_Repr(self->tag));
tag = PyObject_Repr(self->tag);
if (!tag)
return NULL;
sprintf(buffer, " at %p>", self);
PyString_ConcatAndDel(&repr, PyString_FromString(buffer));
repr = PyString_FromFormat("<Element %s at %p>",
PyString_AS_STRING(tag), self);
Py_DECREF(tag);
return repr;
}