You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xml namespace not understood by xml.sax.saxutils.XMLGenerator #49277
The 'xml' namespace in XML files is special in that it need not be
declared. When xml.sax.saxutils.XMLGenerator is used with the namespace
feature it does not know how to handle it.
will produce this error:
...
File "/usr/lib/python2.5/xml/sax/saxutils.py", line 149, in startElementNS
self._write(' %s=%s' % (self._qname(name), quoteattr(value)))
File "/usr/lib/python2.5/xml/sax/saxutils.py", line 107, in _qname
prefix = self._current_context[name[0]]
KeyError: u'http://www.w3.org/XML/1998/namespace'
It can be fixed by making an exception for the xml namespace (as
required by W3C - See http://www.w3.org/XML/1998/namespace) in
xml/sax/saxutils.py. The _qname method could then look like this:
def_qname(self, name):
"""Builds a qualified name from a (ns_url, localname) pair"""ifname[0]:
ifname[0] ==u'http://www.w3.org/XML/1998/namespace':
returnu'xml'+":"+name[1]
# The name is in a non-empty namespaceprefix=self._current_context[name[0]]
ifprefix:
# If it is not the default namespace, prepend the prefixreturnprefix+":"+name[1]
# Return the unqualified namereturnname[1]
I've duplicated the issue and the fix using Python 2.6.2. I'm attaching
Soren Roug's fix in patch form. (I created the patch against r53754 of
saxutils.py.)
I've attached a patch against branches/py3k that tests and fixes the issue.
I don't suppose this fix (if I backport it) could make it into 2.6.6, could it?
troy commented on Aug 6, 2010
troymannequin
Mannequin
More actions
I've created tests and patches for the trunk and branches/py3k. The only difference between the two is the use of u'' for a Unicode string in the trunk. (IIRC, Py3k treats all strings as Unicode.)
It is about a week too late for 2.6.6. rc1 is just out and only critically needed fixes before the final.
For future reference, 'trunk' is frozen. 2.7 patches should be against '2.7maintenace' (or however spelled) but I assume this should apply. 'py3k' is the defacto development trunk. I am not sure what will happen after the switch to hg.
Given that you both agree on the fix, I suspect that this is ready for commit review, but I cannot properly review it. I am trying to get information on who to add to nosy.
troy commented on Aug 6, 2010
troymannequin
Mannequin
More actions
I figured it was probably too late, but one can always hope. :)
While you sort out who gets to review this, I'll see if I can't work out a patch for 2.7. It also occurred to me last night that I should probably add a comment to it. Look for new patches with a day.
There are no specific maintainers for xml.sax.utils. As per RDM's suggestion, Fred or Martin, do either of you have any comments on this or who it might be referred to?
troy commented on Aug 8, 2010
troymannequin
Mannequin
More actions
I'm attaching new patches for 2.7 and 3.2, now with comments. :)
troy commented on Aug 19, 2010
troymannequin
Mannequin
More actions
Hi guys.
I'd like to take a moment to remind everyone that this issue has a small patch with two tests and comments. Please don't let it get lost. :)
“The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace.”
Activity
roug commentedon Jan 21, 2009
The 'xml' namespace in XML files is special in that it need not be
declared. When xml.sax.saxutils.XMLGenerator is used with the namespace
feature it does not know how to handle it.
Example. The code:
executed on the testfile.xml with this content:
<?xml version="1.0"?>
<a:greetings xmlns:a="http://example.com/ns"\>
<a:greet xml:lang="en">Hello world</a:greet>
</a:greetings>
will produce this error:
...
File "/usr/lib/python2.5/xml/sax/saxutils.py", line 149, in startElementNS
self._write(' %s=%s' % (self._qname(name), quoteattr(value)))
File "/usr/lib/python2.5/xml/sax/saxutils.py", line 107, in _qname
prefix = self._current_context[name[0]]
KeyError: u'http://www.w3.org/XML/1998/namespace'
It can be fixed by making an exception for the xml namespace (as
required by W3C - See http://www.w3.org/XML/1998/namespace) in
xml/sax/saxutils.py. The _qname method could then look like this:
troy commentedon Dec 1, 2009
I've duplicated the issue and the fix using Python 2.6.2. I'm attaching
Soren Roug's fix in patch form. (I created the patch against r53754 of
saxutils.py.)
terryjreedy commentedon Aug 4, 2010
Can you add a unittest, based on the example, that fails before and passes after the patch?
Assuming this applies to Py3, make patch against py3k branch (or at least 3.2a1 release), which is now 'trunk'.
That aside, the patch is a simple 2-line addition.
troy commentedon Aug 6, 2010
I've attached a patch against branches/py3k that tests and fixes the issue.
I don't suppose this fix (if I backport it) could make it into 2.6.6, could it?
troy commentedon Aug 6, 2010
I've created tests and patches for the trunk and branches/py3k. The only difference between the two is the use of u'' for a Unicode string in the trunk. (IIRC, Py3k treats all strings as Unicode.)
terryjreedy commentedon Aug 6, 2010
It is about a week too late for 2.6.6. rc1 is just out and only critically needed fixes before the final.
For future reference, 'trunk' is frozen. 2.7 patches should be against '2.7maintenace' (or however spelled) but I assume this should apply. 'py3k' is the defacto development trunk. I am not sure what will happen after the switch to hg.
Given that you both agree on the fix, I suspect that this is ready for commit review, but I cannot properly review it. I am trying to get information on who to add to nosy.
troy commentedon Aug 6, 2010
I figured it was probably too late, but one can always hope. :)
While you sort out who gets to review this, I'll see if I can't work out a patch for 2.7. It also occurred to me last night that I should probably add a comment to it. Look for new patches with a day.
terryjreedy commentedon Aug 7, 2010
There are no specific maintainers for xml.sax.utils. As per RDM's suggestion, Fred or Martin, do either of you have any comments on this or who it might be referred to?
troy commentedon Aug 8, 2010
I'm attaching new patches for 2.7 and 3.2, now with comments. :)
troy commentedon Aug 19, 2010
Hi guys.
I'd like to take a moment to remind everyone that this issue has a small patch with two tests and comments. Please don't let it get lost. :)
Thanks,
Troy
pitrou commentedon Oct 27, 2010
According to http://www.w3.org/TR/xml-names/:
“The prefix xml is by definition bound to the namespace name http://www.w3.org/XML/1998/namespace. It MAY, but need not, be declared, and MUST NOT be bound to any other namespace name. Other prefixes MUST NOT be bound to this namespace name, and it MUST NOT be declared as the default namespace.”
The patch looks good to me.
pitrou commentedon Oct 27, 2010
Committed in r85858 (3.2), r85859 (3.1) and r85860 (2.7). Thank you!