New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
xml namespace not understood by xml.sax.saxutils.XMLGenerator #49277
Comments
The 'xml' namespace in XML files is special in that it need not be Example. The code: import xml.sax, xml.sax.saxutils
parser = xml.sax.make_parser()
parser.setFeature(xml.sax.handler.feature_namespaces, 1)
c = xml.sax.saxutils.XMLGenerator()
parser.setContentHandler(c)
parser.parse('testfile.xml') executed on the testfile.xml with this content: <?xml version="1.0"?> will produce this error: It can be fixed by making an exception for the xml namespace (as def _qname(self, name):
"""Builds a qualified name from a (ns_url, localname) pair"""
if name[0]:
if name[0] == u'http://www.w3.org/XML/1998/namespace':
return u'xml' + ":" + name[1]
# The name is in a non-empty namespace
prefix = self._current_context[name[0]]
if prefix:
# If it is not the default namespace, prepend the prefix
return prefix + ":" + name[1]
# Return the unqualified name
return name[1] |
I've duplicated the issue and the fix using Python 2.6.2. I'm attaching |
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. |
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? |
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. |
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? |
I'm attaching new patches for 2.7 and 3.2, now with comments. :) |
Hi guys. Thanks, |
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. |
Committed in r85858 (3.2), r85859 (3.1) and r85860 (2.7). Thank you! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: