Merge branch 'trunk' into patch-1
This commit is contained in:
commit
14d5941c5f
|
@ -0,0 +1 @@
|
||||||
|
Fixed parsing of streams with Python 3.8 when there are spaces in namespaces or namespaced attributes in twisted.words.xish.domish.ExpatElementStream
|
|
@ -350,6 +350,23 @@ class DomishStreamTestsMixin:
|
||||||
self.elements[0].attributes, {(" bar baz ", "baz"): "quux"})
|
self.elements[0].attributes, {(" bar baz ", "baz"): "quux"})
|
||||||
|
|
||||||
|
|
||||||
|
def test_attributesWithNamespaces(self):
|
||||||
|
"""
|
||||||
|
Attributes with namespace are parsed without Exception.
|
||||||
|
(https://twistedmatrix.com/trac/ticket/9730 regression test)
|
||||||
|
"""
|
||||||
|
|
||||||
|
xml = b"""<root xmlns:test='http://example.org' xml:lang='en'>
|
||||||
|
<test:test>test</test:test>
|
||||||
|
</root>"""
|
||||||
|
|
||||||
|
# with Python 3.8 and without #9730 fix, the following error would
|
||||||
|
# happen at next line:
|
||||||
|
# ``RuntimeError: dictionary keys changed during iteration``
|
||||||
|
self.stream.parse(xml)
|
||||||
|
self.assertEqual(self.elements[0].uri, "http://example.org")
|
||||||
|
|
||||||
|
|
||||||
def testChildPrefix(self):
|
def testChildPrefix(self):
|
||||||
xml = b"<root xmlns='testns' xmlns:foo='testns2'><foo:child/></root>"
|
xml = b"<root xmlns='testns' xmlns:foo='testns2'><foo:child/></root>"
|
||||||
|
|
||||||
|
|
|
@ -807,11 +807,18 @@ class ExpatElementStream:
|
||||||
qname = ('', name)
|
qname = ('', name)
|
||||||
|
|
||||||
# Process attributes
|
# Process attributes
|
||||||
|
newAttrs = {}
|
||||||
|
toDelete = []
|
||||||
for k, v in attrs.items():
|
for k, v in attrs.items():
|
||||||
if " " in k:
|
if " " in k:
|
||||||
aqname = k.rsplit(" ", 1)
|
aqname = k.rsplit(" ", 1)
|
||||||
attrs[(aqname[0], aqname[1])] = v
|
newAttrs[(aqname[0], aqname[1])] = v
|
||||||
del attrs[k]
|
toDelete.append(k)
|
||||||
|
|
||||||
|
attrs.update(newAttrs)
|
||||||
|
|
||||||
|
for k in toDelete:
|
||||||
|
del attrs[k]
|
||||||
|
|
||||||
# Construct the new element
|
# Construct the new element
|
||||||
e = Element(qname, self.defaultNsStack[-1], attrs, self.localPrefixes)
|
e = Element(qname, self.defaultNsStack[-1], attrs, self.localPrefixes)
|
||||||
|
|
Loading…
Reference in New Issue