This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Can't have two tags with the same QName
Type: behavior Stage: resolved
Components: XML Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: bersace, eric.araujo, flox, orsenthil
Priority: normal Keywords: patch

Created on 2010-10-26 19:40 by bersace, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python2.7-fix-qname-already-registered.patch bersace, 2010-10-26 19:40 Fix against ElementTree.py
Messages (4)
msg119643 - (view) Author: Étienne BERSAC (bersace) Date: 2010-10-26 19:40
Hi,

Here is the code to reproduce and the unexcpected behaviour :

21:37:41 bersace@st-francois-de-sales:~/Bureau/$ cat bug.py 
from xml.etree.ElementTree import QName, ElementTree, Element, SubElement
import sys

head = Element(QName('http://www.w3.org/1999/xhtml', 'html'))
SubElement(head, QName('http://www.w3.org/1999/xhtml', 'meta'))
SubElement(head, QName('http://www.w3.org/1999/xhtml', 'meta'))

tree = ElementTree(head)
tree.write(sys.stdout, encoding="utf-8", xml_declaration=True,
           default_namespace='http://www.w3.org/1999/xhtml')
21:38:00 bersace@st-francois-de-sales:~/Bureau/$ python2.7 bug.py 
<?xml version='1.0' encoding='utf-8'?>
Traceback (most recent call last):
  File "bug.py", line 10, in <module>
    default_namespace='http://www.w3.org/1999/xhtml')
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 812, in write
    self._root, encoding, default_namespace
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 880, in _namespaces
    _raise_serialization_error(tag)
  File "/usr/lib/python2.7/xml/etree/ElementTree.py", line 1046, in _raise_serialization_error
    "cannot serialize %r (type %s)" % (text, type(text).__name__)
TypeError: cannot serialize <xml.etree.ElementTree.QName object at 0xb76aa60c> (type QName)
21:38:01 bersace@st-francois-de-sales:~/Bureau/$ 

Patch is attached.

Regards,
Étienne
msg120838 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-09 02:56
Fixed in r86348 for py3k and r86349 for release27-maint.

In release31-maint, I see that there are missing features, like support for xml_declaration and default_namespace, which are however available in release27-maint. This is not a desirable scenario and I not sure why this difference exists. Additionally, the tests in release31-maint are lacking QName tests which are present in py3k and release27-maint. 

Only after these changes, can this be backported to release31-maint.
msg120923 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-11-10 17:03
3.1 was released before 2.7, so there are some features in 2.7 that aren’t in 3.1.  Tests are probably candidate for backport.

(BTW, I don’t understand the fix :)  I guess I fail at boolean logic tonight.)
msg121124 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-11-13 09:31
Thanks for the explanation, Éric. That helps.
- Backported QName tests in r86447 to release31-maint.

As for the logic of the fix, it follows like this:

If True and False:
  #Doesn't go here
elif True:
  # Goes here

vs

if True:
   # Goes here
   if False:
      # Does not matter
elif:
   # Doesn't go here.
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54414
2010-11-13 09:31:19orsenthilsetstatus: open -> closed

messages: + msg121124
2010-11-10 17:03:15eric.araujosetnosy: + eric.araujo
messages: + msg120923
2010-11-09 02:56:29orsenthilsetversions: + Python 3.2
resolution: fixed
messages: + msg120838

assignee: orsenthil
type: behavior
stage: resolved
2010-11-06 06:14:43orsenthilsetnosy: + orsenthil
2010-10-27 11:44:52eric.araujosetnosy: + flox
2010-10-26 19:40:48bersacecreate