[issue11033] ElementTree.fromstring doesn't work with Unicode
Brendan O'Connor added the comment: Sure, go ahead and close it. I was just trying to be helpful and report a bug in the Python standard library. I don't use Python 3.3 so cannot test it. -- nosy: +Brendan.OConnor ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11033] ElementTree.fromstring doesn't work with Unicode
Changes by Alexander Belopolsky alexander.belopol...@gmail.com: -- status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11033] ElementTree.fromstring doesn't work with Unicode
Alexander Belopolsky belopol...@users.sourceforge.net added the comment: This works in 3.x: Python 3.2rc2+ (py3k:88279:88280, Feb 1 2011, 00:01:52) .. from xml.etree import ElementTree ElementTree.fromstring('doc诗/doc') Element 'doc' at 0x1007daa00 In 2.x you need to encode unicode strings before passing them to ElementTree.fromstring(). For example: # encoding: utf-8 from xml.etree import ElementTree t = ElementTree.fromstring(u'doc诗/doc'.encode('utf-8')) print t.text This is not a bug because fromstring() unlike some other ElementTree methods is not documented to support unicode strings. Since 2.x is closed for new features, this has to be rejected. -- assignee: - belopolsky nosy: +belopolsky resolution: - rejected stage: - committed/rejected status: open - pending type: crash - feature request versions: +Python 2.7 -Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11033] ElementTree.fromstring doesn't work with Unicode
STINNER Victor victor.stin...@haypocalc.com added the comment: Since 2.x is closed for new features, this has to be rejected. We can explain in ElementTree documentation how to pass non-ASCII unicode strings: using explicit encoding to UTF-8. -- nosy: +haypo status: pending - open ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11033] ElementTree.fromstring doesn't work with Unicode
Alexander Belopolsky belopol...@users.sourceforge.net added the comment: On Wed, Feb 2, 2011 at 11:10 AM, STINNER Victor rep...@bugs.python.org wrote: .. We can explain in ElementTree documentation how to pass non-ASCII unicode strings: using explicit encoding to UTF-8. ElementTree.fromstring() ultimately calls ElementTree.XMLParser.feed() which is documented as follows: feed(data) Feeds data to the parser. data is encoded data. Maybe we can simply add encoded to the description of ElementTree.fromstring() argument as well? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11033] ElementTree.fromstring doesn't work with Unicode
New submission from Peter Cai newpt...@gmail.com: xml.etree.ElementTree.fromstring doesn't work with Unicode string. See the code below: from xml.etree import ElementTree t = ElementTree.fromstring(u'doc诗/doc') Traceback (most recent call last): File stdin, line 1, in module File D:\Python26\lib\xml\etree\ElementTree.py, line 963, in XML parser.feed(text) File D:\Python26\lib\xml\etree\ElementTree.py, line 1245, in feed self._parser.Parse(data, 0) UnicodeEncodeError: 'ascii' codec can't encode character u'\u8bd7' in position 5 : ordinal not in range(128) -- components: XML messages: 127239 nosy: Peter.Cai priority: normal severity: normal status: open title: ElementTree.fromstring doesn't work with Unicode type: crash versions: Python 2.6 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue11033 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com