diff --git a/sleekxmpp/features/feature_mechanisms/stanza/failure.py b/sleekxmpp/features/feature_mechanisms/stanza/failure.py index 5dd0de56..b9f32605 100644 --- a/sleekxmpp/features/feature_mechanisms/stanza/failure.py +++ b/sleekxmpp/features/feature_mechanisms/stanza/failure.py @@ -47,7 +47,7 @@ class Failure(StanzaBase): def get_condition(self): """Return the condition element's name.""" - for child in self.xml.getchildren(): + for child in self.xml: if "{%s}" % self.namespace in child.tag: cond = child.tag.split('}', 1)[-1] if cond in self.conditions: @@ -68,7 +68,7 @@ class Failure(StanzaBase): def del_condition(self): """Remove the condition element.""" - for child in self.xml.getchildren(): + for child in self.xml: if "{%s}" % self.condition_ns in child.tag: tag = child.tag.split('}', 1)[-1] if tag in self.conditions: diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub.py index 004f0a02..b2fe3010 100644 --- a/sleekxmpp/plugins/xep_0060/stanza/pubsub.py +++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub.py @@ -77,12 +77,12 @@ class Item(ElementBase): self.append(value) def get_payload(self): - childs = self.xml.getchildren() + childs = list(self.xml) if len(childs) > 0: return childs[0] def del_payload(self): - for child in self.xml.getchildren(): + for child in self.xml: self.xml.remove(child) @@ -254,12 +254,12 @@ class PubsubState(ElementBase): self.xml.append(value) def get_payload(self): - childs = self.xml.getchildren() + childs = list(self.xml) if len(childs) > 0: return childs[0] def del_payload(self): - for child in self.xml.getchildren(): + for child in self.xml: self.xml.remove(child) diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py index aeaeefe0..59cf1a50 100644 --- a/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py +++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub_errors.py @@ -33,7 +33,7 @@ class PubsubErrorCondition(ElementBase): def get_condition(self): """Return the condition element's name.""" - for child in self.parent().xml.getchildren(): + for child in self.parent().xml: if "{%s}" % self.condition_ns in child.tag: cond = child.tag.split('}', 1)[-1] if cond in self.conditions: @@ -55,7 +55,7 @@ class PubsubErrorCondition(ElementBase): def del_condition(self): """Remove the condition element.""" - for child in self.parent().xml.getchildren(): + for child in self.parent().xml: if "{%s}" % self.condition_ns in child.tag: tag = child.tag.split('}', 1)[-1] if tag in self.conditions: diff --git a/sleekxmpp/plugins/xep_0060/stanza/pubsub_event.py b/sleekxmpp/plugins/xep_0060/stanza/pubsub_event.py index c0d4929e..32f217fa 100644 --- a/sleekxmpp/plugins/xep_0060/stanza/pubsub_event.py +++ b/sleekxmpp/plugins/xep_0060/stanza/pubsub_event.py @@ -31,12 +31,12 @@ class EventItem(ElementBase): self.xml.append(value) def get_payload(self): - childs = self.xml.getchildren() + childs = list(self.xml) if len(childs) > 0: return childs[0] def del_payload(self): - for child in self.xml.getchildren(): + for child in self.xml: self.xml.remove(child) diff --git a/sleekxmpp/stanza/error.py b/sleekxmpp/stanza/error.py index 809a74b4..8d9266bd 100644 --- a/sleekxmpp/stanza/error.py +++ b/sleekxmpp/stanza/error.py @@ -89,7 +89,7 @@ class Error(ElementBase): def get_condition(self): """Return the condition element's name.""" - for child in self.xml.getchildren(): + for child in self.xml: if "{%s}" % self.condition_ns in child.tag: cond = child.tag.split('}', 1)[-1] if cond in self.conditions: @@ -110,7 +110,7 @@ class Error(ElementBase): def del_condition(self): """Remove the condition element.""" - for child in self.xml.getchildren(): + for child in self.xml: if "{%s}" % self.condition_ns in child.tag: tag = child.tag.split('}', 1)[-1] if tag in self.conditions: diff --git a/sleekxmpp/stanza/iq.py b/sleekxmpp/stanza/iq.py index 47d51b04..f45b3c67 100644 --- a/sleekxmpp/stanza/iq.py +++ b/sleekxmpp/stanza/iq.py @@ -122,7 +122,7 @@ class Iq(RootStanza): def get_query(self): """Return the namespace of the element.""" - for child in self.xml.getchildren(): + for child in self.xml: if child.tag.endswith('query'): ns = child.tag.split('}')[0] if '{' in ns: @@ -132,7 +132,7 @@ class Iq(RootStanza): def del_query(self): """Remove the element.""" - for child in self.xml.getchildren(): + for child in self.xml: if child.tag.endswith('query'): self.xml.remove(child) return self diff --git a/sleekxmpp/test/sleektest.py b/sleekxmpp/test/sleektest.py index 7a3bef24..cac99f77 100644 --- a/sleekxmpp/test/sleektest.py +++ b/sleekxmpp/test/sleektest.py @@ -76,7 +76,7 @@ class SleekTest(unittest.TestCase): known_prefixes[prefix], xml_string) xml = self.parse_xml(xml_string) - xml = xml.getchildren()[0] + xml = list(xml)[0] return xml else: self.fail("XML data was mal-formed:\n%s" % xml_string) @@ -517,9 +517,9 @@ class SleekTest(unittest.TestCase): if '{%s}lang' % xml_ns in recv_xml.attrib: del recv_xml.attrib['{%s}lang' % xml_ns] - if recv_xml.getchildren: + if list(recv_xml): # We received more than just the header - for xml in recv_xml.getchildren(): + for xml in recv_xml: self.xmpp.socket.recv_data(tostring(xml)) attrib = recv_xml.attrib @@ -698,7 +698,7 @@ class SleekTest(unittest.TestCase): if xml.tag.startswith('{'): return xml.tag = '{%s}%s' % (ns, xml.tag) - for child in xml.getchildren(): + for child in xml: self.fix_namespaces(child, ns) def compare(self, xml, *other): @@ -741,7 +741,7 @@ class SleekTest(unittest.TestCase): return False # Step 4: Check children count - if len(xml.getchildren()) != len(other.getchildren()): + if len(list(xml)) != len(list(other)): return False # Step 5: Recursively check children diff --git a/sleekxmpp/xmlstream/matcher/xmlmask.py b/sleekxmpp/xmlstream/matcher/xmlmask.py index 40827312..a0568f08 100644 --- a/sleekxmpp/xmlstream/matcher/xmlmask.py +++ b/sleekxmpp/xmlstream/matcher/xmlmask.py @@ -151,8 +151,8 @@ class MatchXMLMask(MatcherBase): """ tag = tag.split('}')[-1] try: - children = [c.tag.split('}')[-1] for c in xml.getchildren()] + children = [c.tag.split('}')[-1] for c in xml] index = children.index(tag) except ValueError: return None - return xml.getchildren()[index] + return list(xml)[index] diff --git a/sleekxmpp/xmlstream/matcher/xpath.py b/sleekxmpp/xmlstream/matcher/xpath.py index b6af0609..3f03e68e 100644 --- a/sleekxmpp/xmlstream/matcher/xpath.py +++ b/sleekxmpp/xmlstream/matcher/xpath.py @@ -77,10 +77,10 @@ class MatchXPath(MatcherBase): # Skip empty tag name artifacts from the cleanup phase. continue - children = [c.tag.split('}')[-1] for c in xml.getchildren()] + children = [c.tag.split('}')[-1] for c in xml] try: index = children.index(tag) except ValueError: return False - xml = xml.getchildren()[index] + xml = list(xml)[index] return True diff --git a/sleekxmpp/xmlstream/stanzabase.py b/sleekxmpp/xmlstream/stanzabase.py index 766bdb01..a653034e 100644 --- a/sleekxmpp/xmlstream/stanzabase.py +++ b/sleekxmpp/xmlstream/stanzabase.py @@ -445,7 +445,7 @@ class ElementBase(object): return # Initialize values using provided XML - for child in self.xml.getchildren(): + for child in self.xml: if child.tag in self.plugin_tag_map: plugin_class = self.plugin_tag_map[child.tag] self.init_plugin(plugin_class.plugin_attrib, @@ -1050,8 +1050,7 @@ class ElementBase(object): if parent is None: parent = self.xml for element in elements: - if element.tag == original_target or \ - not element.getchildren(): + if element.tag == original_target or not list(element): # Only delete the originally requested elements, and # any parent elements that have become empty. elem_lang = element.attrib.get('{%s}lang' % XML_NS, @@ -1491,7 +1490,7 @@ class StanzaBase(ElementBase): def get_payload(self): """Return a list of XML objects contained in the stanza.""" - return self.xml.getchildren() + return list(self.xml) def set_payload(self, value): """Add XML content to the stanza. diff --git a/sleekxmpp/xmlstream/tostring.py b/sleekxmpp/xmlstream/tostring.py index 379ea09a..2480f9b2 100644 --- a/sleekxmpp/xmlstream/tostring.py +++ b/sleekxmpp/xmlstream/tostring.py @@ -107,7 +107,7 @@ def tostring(xml=None, xmlns='', stanza_ns='', stream=None, if xml.text: output.append(xml_escape(xml.text)) if len(xml): - for child in xml.getchildren(): + for child in xml: output.append(tostring(child, tag_xmlns, stanza_ns, stream)) output.append("" % tag_name) elif xml.text: