Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.

Patch by Serhiy Storchaka.
This commit is contained in:
Eli Bendersky 2013-01-13 05:22:05 -08:00
parent ce1519d250
commit b09b167419
2 changed files with 3 additions and 1 deletions

View file

@ -352,6 +352,8 @@ def find():
'subtext'
>>> ET.ElementTree(elem).findtext("section/tag")
'subtext'
>>> ET.XML('<root><empty /></root>').findtext('empty')
''
>>> summarize_list(elem.findall("."))
['body']
>>> summarize_list(elem.findall("tag"))

View file

@ -840,7 +840,7 @@ element_findtext(ElementObject* self, PyObject* args)
PyObject* text = element_get_text(item);
if (text == Py_None)
return PyBytes_FromString("");
return PyUnicode_FromString("");
Py_XINCREF(text);
return text;
}