[Python-checkins] cpython (merge 3.3 -> default): Issue #16922: fixed findtext() to return empty Unicode string instead of empty
eli.bendersky
python-checkins at python.org
Sun Jan 13 14:27:03 CET 2013
http://hg.python.org/cpython/rev/c38423931724
changeset: 81487:c38423931724
parent: 81483:3e0739b30370
parent: 81486:6323e5f1ed81
user: Eli Bendersky <eliben at gmail.com>
date: Sun Jan 13 05:26:31 2013 -0800
summary:
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
Patch by Serhiy Storchaka.
files:
Lib/test/test_xml_etree.py | 3 +++
Modules/_elementtree.c | 2 +-
2 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1773,6 +1773,9 @@
self.assertIsNone(e.findtext('tog'))
self.assertEqual(e.findtext('tog', 'default'), 'default')
+ # Issue #16922
+ self.assertEqual(ET.XML('<tag><empty /></tag>').findtext('empty'), '')
+
def test_findall(self):
e = ET.XML(SAMPLE_XML)
e[2] = ET.XML(SAMPLE_SECTION)
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -1129,7 +1129,7 @@
PyObject* text = element_get_text(item);
if (text == Py_None)
- return PyBytes_FromString("");
+ return PyUnicode_New(0, 0);
Py_XINCREF(text);
return text;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list