def send(self, element, close=True, defaultUri=None): s = domish.SerializerClass() s.serialize(element, closeElement=close, defaultUri=(defaultUri or NS_JABBER_CLIENT) if close else defaultUri) self.transport.write(s.getValue().encode('utf-8'))
def test_prefixesReuse(self): """ Test that prefixes passed to serialization are not modified. This test makes sure that passing a dictionary of prefixes repeatedly to C{toXml} of elements does not cause serialization errors. A previous implementation changed the passed in dictionary internally, causing havoc later on. """ prefixes = {"testns": "foo"} # test passing of dictionary s = domish.SerializerClass(prefixes=prefixes) self.assertNotIdentical(prefixes, s.prefixes) # test proper serialization on prefixes reuse e = domish.Element(("testns2", "foo"), localPrefixes={"quux": "testns2"}) self.assertEqual("<quux:foo xmlns:quux='testns2'/>", e.toXml(prefixes=prefixes)) e = domish.Element(("testns2", "foo")) self.assertEqual("<foo xmlns='testns2'/>", e.toXml(prefixes=prefixes))