From f7e4caadfe8f63b5aa14d9266e3c722e9ab4007a Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 9 Jan 2019 14:55:27 +0100 Subject: Split tag and attrib only once in tostring(). --- slixmpp/xmlstream/tostring.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/slixmpp/xmlstream/tostring.py b/slixmpp/xmlstream/tostring.py index 6726bf1e..de6fe47d 100644 --- a/slixmpp/xmlstream/tostring.py +++ b/slixmpp/xmlstream/tostring.py @@ -45,11 +45,12 @@ def tostring(xml=None, xmlns='', stream=None, outbuffer='', output = [outbuffer] # Extract the element's tag name. - tag_name = xml.tag.split('}', 1)[-1] + tag_split = xml.tag.split('}', 1) + tag_name = tag_split[-1] # Extract the element's namespace if it is defined. if '}' in xml.tag: - tag_xmlns = xml.tag.split('}', 1)[0][1:] + tag_xmlns = tag_split[0][1:] else: tag_xmlns = '' @@ -82,8 +83,9 @@ def tostring(xml=None, xmlns='', stream=None, outbuffer='', if '}' not in attrib: output.append(' %s="%s"' % (attrib, value)) else: - attrib_ns = attrib.split('}')[0][1:] - attrib = attrib.split('}')[1] + attrib_split = attrib.split('}') + attrib_ns = attrib_split[0][1:] + attrib = attrib_split[1] if attrib_ns == XML_NS: output.append(' xml:%s="%s"' % (attrib, value)) elif stream and attrib_ns in stream.namespace_map: -- cgit v1.2.3