Mercurial > libervia-backend
comparison src/plugins/plugin_xep_0163.py @ 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 | 84a6e83157c2 |
children | 3c304929af74 |
comparison
equal
deleted
inserted
replaced
659:b6c22d9f593a | 660:69a8bfd266a5 |
---|---|
102 def userMoodCB(self, itemsEvent, profile): | 102 def userMoodCB(self, itemsEvent, profile): |
103 if not itemsEvent.items: | 103 if not itemsEvent.items: |
104 debug(_("No item found")) | 104 debug(_("No item found")) |
105 return | 105 return |
106 try: | 106 try: |
107 mood_elem = filter(lambda x: x.name == "mood", itemsEvent.items[0].children)[0] | 107 mood_elt = [child for child in itemsEvent.items[0].elements() if child.name == "mood"][0] |
108 except KeyError: | 108 except IndexError: |
109 error(_("Can't find mood element in mood event")) | 109 error(_("Can't find mood element in mood event")) |
110 return | 110 return |
111 _mood = Mood.fromXml(mood_elem) | 111 mood = Mood.fromXml(mood_elt) |
112 if not _mood: | 112 if not mood: |
113 debug(_("No mood found")) | 113 debug(_("No mood found")) |
114 return | 114 return |
115 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": _mood.value or "", "text": _mood.text or ""}, profile) | 115 self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile) |
116 | 116 |
117 def sendMood(self, data, profile): | 117 def sendMood(self, data, profile): |
118 """Send XEP-0107's User Mood | 118 """Send XEP-0107's User Mood |
119 @param data: must include mood and text | 119 @param data: must include mood and text |
120 @param profile: profile which send the mood""" | 120 @param profile: profile which send the mood""" |
122 value = data['mood'].lower() | 122 value = data['mood'].lower() |
123 text = data['text'] if 'text' in data else '' | 123 text = data['text'] if 'text' in data else '' |
124 except KeyError: | 124 except KeyError: |
125 error(_("Mood data must contain at least 'mood' key")) | 125 error(_("Mood data must contain at least 'mood' key")) |
126 return 3 | 126 return 3 |
127 _mood = UserMood(value, text) | 127 mood = UserMood(value, text) |
128 self.sendPEPEvent(NS_USER_MOOD, _mood, profile) | 128 self.sendPEPEvent(NS_USER_MOOD, mood, profile) |
129 return 0 | 129 return 0 |
130 | 130 |
131 | 131 |
132 class UserMood(Mood, domish.Element): | 132 class UserMood(Mood, domish.Element): |
133 """Improved wokkel Mood which is also a domish.Element""" | 133 """Improved wokkel Mood which is also a domish.Element""" |