diff src/plugins/plugin_xep_0115.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 218149ea1a35
children 6b10442e8920
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0115.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/plugins/plugin_xep_0115.py	Sat Apr 19 19:19:19 2014 +0200
@@ -19,7 +19,8 @@
 
 from sat.core.i18n import _
 from sat.core.constants import Const as C
-from logging import debug, info, error, warning
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from twisted.words.xish import domish
 from twisted.words.protocols.jabber import jid
 from twisted.internet import defer
@@ -52,7 +53,7 @@
     cap_hash = None  # capabilities hash is class variable as it is common to all profiles
 
     def __init__(self, host):
-        info(_("Plugin XEP_0115 initialization"))
+        log.info(_("Plugin XEP_0115 initialization"))
         self.host = host
         host.trigger.add("Disco handled", self._checkHash)
         host.trigger.add("Presence send", self._presenceTrigger)
@@ -69,10 +70,10 @@
             def updateOptimize(optimize):
                 client.caps_optimize = optimize
                 if optimize:
-                    info(_("Caps optimisation enabled"))
+                    log.info(_("Caps optimisation enabled"))
                     client.caps_sent = False
                 else:
-                    warning(_("Caps optimisation not available"))
+                    log.warning(_("Caps optimisation not available"))
             disco_d.addCallback(updateOptimize)
             disco_d.addCallback(lambda dummy: self.recalculateHash(profile))
         return True
@@ -94,8 +95,8 @@
         for item in _infos:
             disco_infos.append(item)
         cap_hash = self.host.memory.disco.generateHash(disco_infos)
-        info("Our capability hash has been generated: [%s]" % cap_hash)
-        debug("Generating capability domish.Element")
+        log.info("Our capability hash has been generated: [%s]" % cap_hash)
+        log.debug("Generating capability domish.Element")
         c_elt = domish.Element((NS_ENTITY_CAPABILITY, 'c'))
         c_elt['hash'] = 'sha-1'
         c_elt['node'] = C.APP_URL
@@ -140,21 +141,21 @@
             c_hash = c_elem['hash']
             c_node = c_elem['node']
         except KeyError:
-            warning(_('Received invalid capabilities tag'))
+            log.warning(_('Received invalid capabilities tag'))
             return
 
         if c_ver in self.host.memory.disco.hashes:
             # we already know the hash, we update the jid entity
-            debug ("hash [%(hash)s] already in cache, updating entity [%(jid)s]" % {'hash': c_ver, 'jid': from_jid.full()})
+            log.debug ("hash [%(hash)s] already in cache, updating entity [%(jid)s]" % {'hash': c_ver, 'jid': from_jid.full()})
             self.host.memory.updateEntityData(from_jid, C.ENTITY_CAP_HASH, c_ver, self.profile)
             return
 
         yield self.host.getDiscoInfos(from_jid, self.profile)
         if c_hash != 'sha-1':
             #unknown hash method
-            warning(_('Unknown hash method for entity capabilities: [%(hash_method)s] (entity: %(jid)s, node: %(node)s)') % {'hash_method':c_hash, 'jid': from_jid, 'node': c_node})
+            log.warning(_('Unknown hash method for entity capabilities: [%(hash_method)s] (entity: %(jid)s, node: %(node)s)') % {'hash_method':c_hash, 'jid': from_jid, 'node': c_node})
         computed_hash = self.host.memory.getEntityDatum(from_jid, C.ENTITY_CAP_HASH, self.profile)
         if computed_hash != c_ver:
-            warning(_('Computed hash differ from given hash:\ngiven: [%(given_hash)s]\ncomputed: [%(computed_hash)s]\n(entity: %(jid)s, node: %(node)s)') % {'given_hash':c_ver, 'computed_hash': computed_hash, 'jid': from_jid, 'node': c_node})
+            log.warning(_('Computed hash differ from given hash:\ngiven: [%(given_hash)s]\ncomputed: [%(computed_hash)s]\n(entity: %(jid)s, node: %(node)s)') % {'given_hash':c_ver, 'computed_hash': computed_hash, 'jid': from_jid, 'node': c_node})
 
         # TODO: me must manage the full algorithm described at XEP-0115 #5.4 part 3