diff src/plugins/plugin_xep_0047.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 c6d8fc63b1db
children 069ad98b360d
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0047.py	Sat Apr 19 16:48:26 2014 +0200
+++ b/src/plugins/plugin_xep_0047.py	Sat Apr 19 19:19:19 2014 +0200
@@ -18,7 +18,8 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from sat.core.i18n import _
-from logging import debug, info, warning, error
+from sat.core.log import getLogger
+log = getLogger(__name__)
 from twisted.words.protocols.jabber import client as jabber_client, jid
 from twisted.words.xish import domish
 from twisted.internet import reactor
@@ -59,7 +60,7 @@
     NAMESPACE = NS_IBB
 
     def __init__(self, host):
-        info(_("In-Band Bytestreams plugin initialization"))
+        log.info(_("In-Band Bytestreams plugin initialization"))
         self.host = host
 
     def getHandler(self, profile):
@@ -72,7 +73,7 @@
     def _timeOut(self, sid, profile):
         """Delecte current_stream id, called after timeout
         @param id: id of client.xep_0047_current_stream"""
-        info(_("In-Band Bytestream: TimeOut reached for id %(sid)s [%(profile)s]")
+        log.info(_("In-Band Bytestream: TimeOut reached for id %(sid)s [%(profile)s]")
              % {"sid": sid, "profile": profile})
         self._killId(sid, False, "TIMEOUT", profile)
 
@@ -82,7 +83,7 @@
         assert(profile)
         client = self.host.getClient(profile)
         if sid not in client.xep_0047_current_stream:
-            warning(_("kill id called on a non existant id"))
+            log.warning(_("kill id called on a non existant id"))
             return
         if "observer_cb" in client.xep_0047_current_stream[sid]:
             client.xmlstream.removeObserver(client.xep_0047_current_stream[sid]["event_data"], client.xep_0047_current_stream[sid]["observer_cb"])
@@ -134,7 +135,7 @@
         data["failure_cb"] = failure_cb
 
     def streamOpening(self, IQ, profile):
-        debug(_("IBB stream opening"))
+        log.debug(_("IBB stream opening"))
         IQ.handled = True
         client = self.host.getClient(profile)
         open_elt = IQ.firstChildElement()
@@ -142,15 +143,15 @@
         sid = open_elt.getAttribute('sid')
         stanza = open_elt.getAttribute('stanza', 'iq')
         if not sid or not block_size or int(block_size) > 65535:
-            warning(_("malformed IBB transfer: %s" % IQ['id']))
+            log.warning(_("malformed IBB transfer: %s" % IQ['id']))
             self.sendNotAcceptableError(IQ['id'], IQ['from'], client.xmlstream)
             return
         if not sid in client.xep_0047_current_stream:
-            warning(_("Ignoring unexpected IBB transfer: %s" % sid))
+            log.warning(_("Ignoring unexpected IBB transfer: %s" % sid))
             self.sendNotAcceptableError(IQ['id'], IQ['from'], client.xmlstream)
             return
         if client.xep_0047_current_stream[sid]["from"] != jid.JID(IQ['from']):
-            warning(_("sended jid inconsistency (man in the middle attack attempt ?)"))
+            log.warning(_("sended jid inconsistency (man in the middle attack attempt ?)"))
             self.sendNotAcceptableError(IQ['id'], IQ['from'], client.xmlstream)
             self._killId(sid, False, "PROTOCOL_ERROR", profile=profile)
             return
@@ -177,7 +178,7 @@
     def streamClosing(self, IQ, profile):
         IQ.handled = True
         client = self.host.getClient(profile)
-        debug(_("IBB stream closing"))
+        log.debug(_("IBB stream closing"))
         data_elt = IQ.firstChildElement()
         sid = data_elt.getAttribute('sid')
         result = domish.Element((None, 'iq'))
@@ -212,21 +213,21 @@
         client = self.host.getClient(profile)
         sid = data_elt.getAttribute('sid')
         if sid not in client.xep_0047_current_stream:
-            error(_("Received data for an unknown session id"))
+            log.error(_("Received data for an unknown session id"))
             return False
 
         from_jid = client.xep_0047_current_stream[sid]["from"]
         file_obj = client.xep_0047_current_stream[sid]["file_obj"]
 
         if stanza_from_jid != from_jid:
-            warning(_("sended jid inconsistency (man in the middle attack attempt ?)"))
+            log.warning(_("sended jid inconsistency (man in the middle attack attempt ?)"))
             if stanza == 'iq':
                 self.sendNotAcceptableError(sid, from_jid, client.xmlstream)
             return False
 
         client.xep_0047_current_stream[sid]["seq"] += 1
         if int(data_elt.getAttribute("seq", -1)) != client.xep_0047_current_stream[sid]["seq"]:
-            warning(_("Sequence error"))
+            log.warning(_("Sequence error"))
             if stanza == 'iq':
                 self.sendNotAcceptableError(data_elt["id"], from_jid, client.xmlstream)
             return False
@@ -239,7 +240,7 @@
             file_obj.write(base64.b64decode(str(data_elt)))
         except TypeError:
             #The base64 data is invalid
-            warning(_("Invalid base64 data"))
+            log.warning(_("Invalid base64 data"))
             if stanza == 'iq':
                 self.sendNotAcceptableError(data_elt["id"], from_jid, client.xmlstream)
             return False
@@ -270,7 +271,7 @@
         @param profile: %(doc_profile)s"""
         client = self.host.getClient(profile)
         if length is not None:
-            error(_('stream length not managed yet'))
+            log.error(_('stream length not managed yet'))
             return
         data = client.xep_0047_current_stream[sid] = {}
         data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid)
@@ -297,7 +298,7 @@
         client = self.host.getClient(profile)
         data = client.xep_0047_current_stream[sid]
         if iq_elt["type"] == "error":
-            warning(_("Transfer failed"))
+            log.warning(_("Transfer failed"))
             self.terminateStream(sid, "IQ_ERROR")
             return