Mercurial > libervia-backend
diff src/core/xmpp.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 | 3a22c011fdbd |
children | 6e975c6b0faf |
line wrap: on
line diff
--- a/src/core/xmpp.py Sat Apr 19 16:48:26 2014 +0200 +++ b/src/core/xmpp.py Sat Apr 19 19:19:19 2014 +0200 @@ -22,7 +22,8 @@ from twisted.internet import task, defer from twisted.words.protocols.jabber import jid, xmlstream from wokkel import client, disco, xmppim, generic, compat, delay, iwokkel -from logging import debug, info, warning, error +from sat.core.log import getLogger +log = getLogger(__name__) from sat.core import exceptions from calendar import timegm from zope.interface import implements @@ -54,13 +55,13 @@ return client.XMPPClient._authd(self, xmlstream) self.__connected = True - info(_("********** [%s] CONNECTED **********") % self.profile) + log.info(_("********** [%s] CONNECTED **********") % self.profile) self.streamInitialized() self.host_app.bridge.connected(self.profile) # we send the signal to the clients def streamInitialized(self): """Called after _authd""" - debug(_("XML stream is initialized")) + log.debug(_("XML stream is initialized")) self.keep_alife = task.LoopingCall(self.xmlstream.send, " ") # Needed to avoid disconnection (specially with openfire) self.keep_alife.start(180) @@ -81,7 +82,7 @@ disco_d.addCallback(finish_connection) def initializationFailed(self, reason): - error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason})) + log.error(_("ERROR: XMPP connection failed for profile '%(profile)s': %(reason)s" % {'profile': self.profile, 'reason': reason})) self.host_app.bridge.connectionError("AUTH_ERROR", self.profile) try: client.XMPPClient.initializationFailed(self, reason) @@ -95,11 +96,11 @@ def connectionLost(self, connector, unused_reason): self.__connected = False - info(_("********** [%s] DISCONNECTED **********") % self.profile) + log.info(_("********** [%s] DISCONNECTED **********") % self.profile) try: self.keep_alife.stop() except AttributeError: - debug(_("No keep_alife")) + log.debug(_("No keep_alife")) self.host_app.bridge.disconnected(self.profile) # we send the signal to the clients self.host_app.purgeClient(self.profile) # and we remove references to this client @@ -111,7 +112,7 @@ self.host = host def onMessage(self, message): - debug(_(u"got message from: %s"), message["from"]) + log.debug(_(u"got message from: %s") % message["from"]) post_treat = defer.Deferred() # XXX: plugin can add their treatments to this deferred if not self.host.trigger.point("MessageReceived", message, post_treat, profile=self.parent.profile): @@ -163,7 +164,7 @@ def requestRoster(self): """ ask the server for Roster list """ - debug("requestRoster") + log.debug("requestRoster") d = self.getRoster().addCallback(self.rosterCb) d.chainDeferred(self.got_roster) @@ -217,11 +218,11 @@ # may change in the future self.removeItem(item.jid) return - info(_("new contact in roster list: %s"), item.jid.full()) + log.info(_("new contact in roster list: %s") % item.jid.full()) if not item.subscriptionTo: - warning(_("You are not subscribed to this contact !")) + log.warning(_("You are not subscribed to this contact !")) if not item.subscriptionFrom: - warning(_("This contact is not subscribed to you !")) + log.warning(_("This contact is not subscribed to you !")) #self.host.memory.addContact(item.jid, item_attr, item.groups, self.parent.profile) bare_jid = item.jid.userhostJID() @@ -239,7 +240,7 @@ try: item = self._jids.pop(bare_jid) except KeyError: - warning("Received a roster remove event for an item not in cache") + log.warning("Received a roster remove event for an item not in cache") return for group in item.groups: try: @@ -248,7 +249,7 @@ if not jids_set: del self._groups[group] except KeyError: - warning("there is not cache for the group [%(groups)s] of the removed roster item [%(jid)s]" % + log.warning("there is not cache for the group [%(groups)s] of the removed roster item [%(jid)s]" % {"group": group, "jid": bare_jid}) # then we send the bridge signal @@ -295,7 +296,7 @@ super(SatPresenceProtocol, self).send(obj) def availableReceived(self, entity, show=None, statuses=None, priority=0): - debug(_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, 'show': show, 'statuses': statuses, 'priority': priority}) + log.debug(_("presence update for [%(entity)s] (available, show=%(show)s statuses=%(statuses)s priority=%(priority)d)") % {'entity': entity, 'show': show, 'statuses': statuses, 'priority': priority}) if not statuses: statuses = {} @@ -314,7 +315,7 @@ self.parent.profile) def unavailableReceived(self, entity, statuses=None): - debug(_("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity': entity, 'statuses': statuses}) + log.debug(_("presence update for [%(entity)s] (unavailable, statuses=%(statuses)s)") % {'entity': entity, 'statuses': statuses}) if not statuses: statuses = {} @@ -358,7 +359,7 @@ self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) item = self.parent.roster.getItem(entity) if not item or not item.subscriptionTo: # we automatically subscribe to 'to' presence - debug(_('sending automatic "from" subscription request')) + log.debug(_('sending automatic "from" subscription request')) self.subscribe(entity) def unsubscribed(self, entity): @@ -366,29 +367,29 @@ self.host.memory.delWaitingSub(entity.userhost(), self.parent.profile) def subscribedReceived(self, entity): - debug(_("subscription approved for [%s]") % entity.userhost()) + log.debug(_("subscription approved for [%s]") % entity.userhost()) self.host.bridge.subscribe('subscribed', entity.userhost(), self.parent.profile) def unsubscribedReceived(self, entity): - debug(_("unsubscription confirmed for [%s]") % entity.userhost()) + log.debug(_("unsubscription confirmed for [%s]") % entity.userhost()) self.host.bridge.subscribe('unsubscribed', entity.userhost(), self.parent.profile) def subscribeReceived(self, entity): - debug(_("subscription request from [%s]") % entity.userhost()) + log.debug(_("subscription request from [%s]") % entity.userhost()) item = self.parent.roster.getItem(entity) if item and item.subscriptionTo: # We automatically accept subscription if we are already subscribed to contact presence - debug(_('sending automatic subscription acceptance')) + log.debug(_('sending automatic subscription acceptance')) self.subscribed(entity) else: self.host.memory.addWaitingSub('subscribe', entity.userhost(), self.parent.profile) self.host.bridge.subscribe('subscribe', entity.userhost(), self.parent.profile) def unsubscribeReceived(self, entity): - debug(_("unsubscription asked for [%s]") % entity.userhost()) + log.debug(_("unsubscription asked for [%s]") % entity.userhost()) item = self.parent.roster.getItem(entity) if item and item.subscriptionFrom: # we automatically remove contact - debug(_('automatic contact deletion')) + log.debug(_('automatic contact deletion')) self.host.delContact(entity, self.parent.profile) self.host.bridge.subscribe('unsubscribe', entity.userhost(), self.parent.profile) @@ -405,7 +406,7 @@ def iqFallback(self, iq): if iq.handled is True: return - debug(u"iqFallback: xml = [%s]" % (iq.toXml())) + log.debug(u"iqFallback: xml = [%s]" % (iq.toXml())) generic.FallbackHandler.iqFallback(self, iq) @@ -441,14 +442,14 @@ iq.send(self.jabber_host).addCallbacks(self.registrationAnswer, self.registrationFailure) def registrationAnswer(self, answer): - debug(_("registration answer: %s") % answer.toXml()) + log.debug(_("registration answer: %s") % answer.toXml()) answer_type = "SUCCESS" answer_data = {"message": _("Registration successfull")} self.host.bridge.actionResult(answer_type, self.answer_id, answer_data, self.profile) self.xmlstream.sendFooter() def registrationFailure(self, failure): - info(_("Registration failure: %s") % str(failure.value)) + log.info(_("Registration failure: %s") % str(failure.value)) answer_type = "ERROR" answer_data = {} if failure.value.condition == 'conflict':