Commit 9f1340b9 authored by Martin v. Löwis's avatar Martin v. Löwis

Do not use the default namespace for attributes.

Fixes http://bugs.debian.org/229885
Will backport to 2.3.
parent d7911a33
...@@ -13,6 +13,8 @@ testdoc = """\ ...@@ -13,6 +13,8 @@ testdoc = """\
<greeting>Hello, world!</greeting> <greeting>Hello, world!</greeting>
""" """
nsdoc = "<foo xmlns='URI' attr='val'/>"
import warnings import warnings
warnings.filterwarnings("ignore", ".* xmllib .* obsolete.*", warnings.filterwarnings("ignore", ".* xmllib .* obsolete.*",
DeprecationWarning, r'xmllib$') DeprecationWarning, r'xmllib$')
...@@ -29,6 +31,18 @@ class XMLParserTestCase(unittest.TestCase): ...@@ -29,6 +31,18 @@ class XMLParserTestCase(unittest.TestCase):
parser.feed(c) parser.feed(c)
parser.close() parser.close()
def test_default_namespace(self):
class H(xmllib.XMLParser):
def unknown_starttag(self, name, attr):
self.name, self.attr = name, attr
h=H()
h.feed(nsdoc)
h.close()
# The default namespace applies to elements...
self.assertEquals(h.name, "URI foo")
# but not to attributes
self.assertEquals(h.attr, {'attr':'val'})
def test_main(): def test_main():
test_support.run_unittest(XMLParserTestCase) test_support.run_unittest(XMLParserTestCase)
......
...@@ -6,8 +6,7 @@ import re ...@@ -6,8 +6,7 @@ import re
import string import string
import warnings import warnings
warnings.warn("The xmllib module is obsolete. Use xml.sax instead.", warnings.warn("The xmllib module is obsolete. Use xml.sax instead.", DeprecationWarning)
DeprecationWarning)
del warnings del warnings
version = '0.3' version = '0.3'
...@@ -641,20 +640,17 @@ class XMLParser: ...@@ -641,20 +640,17 @@ class XMLParser:
aprefix, key = res.group('prefix', 'local') aprefix, key = res.group('prefix', 'local')
if self.__map_case: if self.__map_case:
key = key.lower() key = key.lower()
if aprefix is None: if aprefix is not None:
aprefix = ''
ans = None ans = None
for t, d, nst in self.stack: for t, d, nst in self.stack:
if aprefix in d: if aprefix in d:
ans = d[aprefix] ans = d[aprefix]
if ans is None and aprefix != '': if ans is None:
ans = self.__namespaces.get(aprefix) ans = self.__namespaces.get(aprefix)
if ans is not None: if ans is not None:
key = ans + ' ' + key key = ans + ' ' + key
elif aprefix != '': else:
key = aprefix + ':' + key key = aprefix + ':' + key
elif ns is not None:
key = ns + ' ' + key
nattrdict[key] = val nattrdict[key] = val
attrnamemap[key] = okey attrnamemap[key] = okey
attrdict = nattrdict attrdict = nattrdict
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment