[issue16913] ElementTree tostring error when method='text'
Serhiy Storchaka added the comment: Can you please provide an example of data for which the tostring method fails? I can't reproduce this on simple data. import xml.etree.ElementTree as ET ET.tostring(ET.XML('rootbq/bwerty/root'), method='text', encoding='unicode') 'qwerty' -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Serhiy Storchaka added the comment: I found such example. It happens when the data contains XML entity. ET.tostring(ET.XML('rootaamp;/root'), method='text', encoding='unicode') Traceback (most recent call last): File stdin, line 1, in module File /home/serhiy/py/cpython/Lib/xml/etree/ElementTree.py, line 1171, in tostring ElementTree(element).write(stream, encoding, method=method) File /home/serhiy/py/cpython/Lib/xml/etree/ElementTree.py, line 824, in write _serialize_text(write, self._root) File /home/serhiy/py/cpython/Lib/xml/etree/ElementTree.py, line 1057, in _serialize_text write(part) TypeError: string argument expected, got 'list' Indeed, itertext() returns a list of lists instead of list of strings. list(ET.XML('rootaamp;/root').itertext()) [['a', '']] The bug is in the C implementation of itertext(). -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Frank added the comment: It happens whenever the method is called, regardless of input. I'm using HTML that has been tidied first with HTML entities (if any) converted to unicode values. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Frank added the comment: Scratch that, it happens whenever there are XML entities (lt;, quot; and friends) that are appearing the text as you pointed out. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Serhiy Storchaka added the comment: Here is a patch for 3.3+. 2.7 and 3.2 are not affected. -- keywords: +patch stage: needs patch - patch review versions: +Python 3.4 Added file: http://bugs.python.org/file28666/etree_itertext.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Roundup Robot added the comment: New changeset d965ff47cf94 by Eli Bendersky in branch '3.3': Issue #16913: Fix Element.itertext()'s handling of text with XML entities. http://hg.python.org/cpython/rev/d965ff47cf94 New changeset 9ab8632e7213 by Eli Bendersky in branch 'default': Issue #16913: Fix Element.itertext()'s handling of text with XML entities. http://hg.python.org/cpython/rev/9ab8632e7213 -- nosy: +python-dev ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Eli Bendersky added the comment: Fixed. Thanks. -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
New submission from Frank: Since upgrading to python 3.3 the tostring method fails when the output method is requested as text. Code like this: with open(fp, mode='rt') as f: data = f.read() tree, idmap = ET.XMLID(data) print(ET.tostring(tree, method='text', encoding='unicode')) Generates the following error: Traceback (most recent call last): File /home/john/Desktop/docs/Pear/pear.py, line 64, in pass_four print(ET.tostring(tree, method='text', encoding='unicode')) File /usr/lib/python3.3/xml/etree/ElementTree.py, line 1171, in tostring ElementTree(element).write(stream, encoding, method=method) File /usr/lib/python3.3/xml/etree/ElementTree.py, line 824, in write _serialize_text(write, self._root) File /usr/lib/python3.3/xml/etree/ElementTree.py, line 1057, in _serialize_text write(part) TypeError: string argument expected, got 'list' Whereas it used to return plain text with formatting tags stripped from the root element on prior versions of python. -- components: XML messages: 179523 nosy: Frank priority: normal severity: normal status: open title: ElementTree tostring error when method='text' versions: Python 3.3 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16913] ElementTree tostring error when method='text'
Changes by Ezio Melotti ezio.melo...@gmail.com: -- keywords: +3.3regression nosy: +eli.bendersky, ezio.melotti stage: - needs patch type: - behavior ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16913 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com