changeset 660:69a8bfd266a5

core, plugins: fixed bad use of children instead of elements() for domish.Element instances.
author Goffi <goffi@goffi.org>
date Tue, 15 Oct 2013 19:28:34 +0200
parents b6c22d9f593a
children d81f55a58c08
files src/plugins/plugin_misc_groupblog.py src/plugins/plugin_misc_quiz.py src/plugins/plugin_xep_0020.py src/plugins/plugin_xep_0085.py src/plugins/plugin_xep_0163.py src/plugins/plugin_xep_0277.py src/tools/xml_tools.py
diffstat 7 files changed, 19 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_groupblog.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/plugins/plugin_misc_groupblog.py	Tue Oct 15 19:28:34 2013 +0200
@@ -212,7 +212,7 @@
 
     def _parseAccessData(self, microblog_data, item):
         P = self.host.plugins["XEP-0060"]
-        form_elts = filter(lambda elt: elt.name == "x", item.children)
+        form_elts = [child for child in item.elements() if child.name == "x"]
         for form_elt in form_elts:
             form = data_form.Form.fromElement(form_elt)
 
--- a/src/plugins/plugin_misc_quiz.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/plugins/plugin_misc_quiz.py	Tue Oct 15 19:28:34 2013 +0200
@@ -146,7 +146,7 @@
         @param answer_result_elt: answer result element
         @return: (player, good_answer, score)"""
         score = {}
-        for score_elt in answer_result_elt.children:
+        for score_elt in answer_result_elt.elements():
             score[score_elt['player']] = int(score_elt['score'])
         return (answer_result_elt['player'], answer_result_elt['good_answer'] == str(True), score)
 
--- a/src/plugins/plugin_xep_0020.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/plugins/plugin_xep_0020.py	Tue Oct 15 19:28:34 2013 +0200
@@ -55,7 +55,7 @@
         """Check element's children to find feature elements
         @param elt: domish.Element
         @return: feature elements"""
-        return filter(lambda elt: elt.name == 'feature', elt.elements())
+        return [child for child in elt.elements() if child.name == 'feature']
 
     def getChoosedOptions(self, elt):
         """Return choosed feature for feature element
--- a/src/plugins/plugin_xep_0085.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/plugins/plugin_xep_0085.py	Tue Oct 15 19:28:34 2013 +0200
@@ -27,7 +27,7 @@
 except ImportError:
     from wokkel.subprotocols import XMPPHandler
 from threading import Timer
-from twisted.words.xish.domish import generateElementsNamed
+from twisted.words.xish import domish
 
 NS_XMPP_CLIENT = "jabber:client"
 NS_CHAT_STATES = "http://jabber.org/protocol/chatstates"
@@ -143,10 +143,10 @@
             return True
 
         try:
-            generateElementsNamed(message.children, name="body").next()
+            domish.generateElementsNamed(message.elements(), name="body").next()
             from_jid = JID(message.getAttribute("from"))
             try:
-                generateElementsNamed(message.children, name="active").next()
+                domish.generateElementsNamed(message.elements(), name="active").next()
                 # contact enabled Chat State Notifications
                 self.updateEntityData(from_jid, True, profile)
                 # init to send following "composing" state
@@ -158,7 +158,7 @@
         except StopIteration:
             pass
 
-        state_list = [child.name for child in message.children if
+        state_list = [child.name for child in message.elements() if
                       message.getAttribute("type") in MESSAGE_TYPES
                       and child.name in CHAT_STATES
                       and child.defaultUri == NS_CHAT_STATES]
@@ -178,7 +178,7 @@
             return True
         try:
             # message with a body always mean active state
-            generateElementsNamed(message.children, name="body").next()
+            domish.generateElementsNamed(message.elements(), name="body").next()
             message.addElement('active', NS_CHAT_STATES)
             # launch the chat state machine (init the timer)
             self.__chatStateActive(to_jid, mess_data["type"], profile)
--- a/src/plugins/plugin_xep_0163.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/plugins/plugin_xep_0163.py	Tue Oct 15 19:28:34 2013 +0200
@@ -104,15 +104,15 @@
             debug(_("No item found"))
             return
         try:
-            mood_elem = filter(lambda x: x.name == "mood", itemsEvent.items[0].children)[0]
-        except KeyError:
+            mood_elt = [child for child in itemsEvent.items[0].elements() if child.name == "mood"][0]
+        except IndexError:
             error(_("Can't find mood element in mood event"))
             return
-        _mood = Mood.fromXml(mood_elem)
-        if not _mood:
+        mood = Mood.fromXml(mood_elt)
+        if not mood:
             debug(_("No mood found"))
             return
-        self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": _mood.value or "", "text": _mood.text or ""}, profile)
+        self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile)
 
     def sendMood(self, data, profile):
         """Send XEP-0107's User Mood
@@ -124,8 +124,8 @@
         except KeyError:
             error(_("Mood data must contain at least 'mood' key"))
             return 3
-        _mood = UserMood(value, text)
-        self.sendPEPEvent(NS_USER_MOOD, _mood, profile)
+        mood = UserMood(value, text)
+        self.sendPEPEvent(NS_USER_MOOD, mood, profile)
         return 0
 
 
--- a/src/plugins/plugin_xep_0277.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/plugins/plugin_xep_0277.py	Tue Oct 15 19:28:34 2013 +0200
@@ -85,8 +85,8 @@
         @param item: domish.Element of microblog item
         @return: microblog data (dictionary)"""
         try:
-            entry_elt = filter(lambda x: x.name == "entry", item.children)[0]
-        except KeyError:
+            entry_elt = [child for child in item.elements() if child.name == "entry"][0]
+        except IndexError:
             warning(_('No entry element in microblog item'))
             return
         _entry = atom.Entry().import_xml(entry_elt.toXml().encode('utf-8'))
--- a/src/tools/xml_tools.py	Mon Oct 07 13:09:57 2013 +0200
+++ b/src/tools/xml_tools.py	Tue Oct 15 19:28:34 2013 +0200
@@ -75,7 +75,7 @@
     except StopIteration:
         raise exceptions.DataError("Couldn't find expected <reported> tag")
 
-    for elt in reported_elt.children:
+    for elt in reported_elt.elements():
         if elt.name != "field":
             raise exceptions.DataError("Unexpected tag")
         name = elt["var"]
@@ -90,7 +90,7 @@
 
     for item_elt in item_elts:
         fields = []
-        for elt in item_elt.children:
+        for elt in item_elt.elements():
             if elt.name != 'field':
                 warning("Unexpected tag (%s)" % elt.name)
                 continue