diff src/plugins/plugin_xep_0163.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents 1a759096ccbd
children 069ad98b360d
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0163.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/plugins/plugin_xep_0163.py	Sat Apr 19 19:19:19 2014 +0200
@@ -18,17 +18,14 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat.core.i18n import _
+from sat.core import exceptions
 from sat.core.constants import Const as C
-from logging import debug, info, error
-from twisted.internet import protocol
-from twisted.words.protocols.jabber import client, jid
-from twisted.words.protocols.jabber import error as jab_error
-import twisted.internet.error
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from twisted.words.xish import domish
 
 from wokkel import disco, pubsub
 from wokkel.formats import Mood
-from sat.core import exceptions
 
 NS_USER_MOOD = 'http://jabber.org/protocol/mood'
 
@@ -47,7 +44,7 @@
 class XEP_0163(object):
 
     def __init__(self, host):
-        info(_("PEP plugin initialization"))
+        log.info(_("PEP plugin initialization"))
         self.host = host
         self.pep_events = set()
         self.pep_out_cb = {}
@@ -95,25 +92,25 @@
         """
         profile = self.host.memory.getProfileName(profile_key)
         if not profile:
-            error(_('Trying to send personal event with an unknown profile key [%s]') % profile_key)
+            log.error(_('Trying to send personal event with an unknown profile key [%s]') % profile_key)
             raise exceptions.ProfileUnknownError
         if not event_type in self.pep_out_cb.keys():
-            error(_('Trying to send personal event for an unknown type'))
-            raise DataError('Type unknown')
+            log.error(_('Trying to send personal event for an unknown type'))
+            raise exceptions.DataError('Type unknown')
         return self.pep_out_cb[event_type](data, profile)
 
     def userMoodCB(self, itemsEvent, profile):
         if not itemsEvent.items:
-            debug(_("No item found"))
+            log.debug(_("No item found"))
             return
         try:
             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"))
+            log.error(_("Can't find mood element in mood event"))
             return
         mood = Mood.fromXml(mood_elt)
         if not mood:
-            debug(_("No mood found"))
+            log.debug(_("No mood found"))
             return
         self.host.bridge.personalEvent(itemsEvent.sender.full(), "MOOD", {"mood": mood.value or "", "text": mood.text or ""}, profile)