From: Eli Bendersky Date: Sun, 13 Jan 2013 13:22:05 +0000 (-0800) Subject: Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes... X-Git-Tag: v3.2.4rc1~224 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b09b16741930e614d95cc51172f0106e3c8ecc00;p=thirdparty%2FPython%2Fcpython.git Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text. Patch by Serhiy Storchaka. --- diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 3092f3bc11ed..f61292f54684 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -352,6 +352,8 @@ def find(): 'subtext' >>> ET.ElementTree(elem).findtext("section/tag") 'subtext' + >>> ET.XML('').findtext('empty') + '' >>> summarize_list(elem.findall(".")) ['body'] >>> summarize_list(elem.findall("tag")) diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index c36af5d12616..17d5d09962e3 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -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; }