comparison src/plugins/plugin_xep_0033.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 c897c8d321b3
children c37a24922f27
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
16 16
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 import logging 21 from sat.core.log import getLogger
22 from sat.core import exceptions 22 log = getLogger(__name__)
23 from wokkel import disco, iwokkel 23 from wokkel import disco, iwokkel
24 from zope.interface import implements 24 from zope.interface import implements
25 from twisted.words.protocols.jabber.jid import JID 25 from twisted.words.protocols.jabber.jid import JID
26 from twisted.python.failure import Failure 26 from twisted.python.failure import Failure
27 import copy 27 import copy
28 try: 28 try:
29 from twisted.words.protocols.xmlstream import XMPPHandler 29 from twisted.words.protocols.xmlstream import XMPPHandler
30 except ImportError: 30 except ImportError:
31 from wokkel.subprotocols import XMPPHandler 31 from wokkel.subprotocols import XMPPHandler
32 from threading import Timer
33 from twisted.words.xish import domish 32 from twisted.words.xish import domish
34 from twisted.internet import defer, threads 33 from twisted.internet import defer
35 34
36 from sat.core.sat_main import MessageSentAndStored, AbortSendMessage 35 from sat.core.sat_main import MessageSentAndStored, AbortSendMessage
37 from sat.tools.misc import TriggerManager 36 from sat.tools.misc import TriggerManager
38 from time import time 37 from time import time
39 38
68 class XEP_0033(object): 67 class XEP_0033(object):
69 """ 68 """
70 Implementation for XEP 0033 69 Implementation for XEP 0033
71 """ 70 """
72 def __init__(self, host): 71 def __init__(self, host):
73 logging.info(_("Extended Stanza Addressing plugin initialization")) 72 log.info(_("Extended Stanza Addressing plugin initialization"))
74 self.host = host 73 self.host = host
75 self.internal_data = {} 74 self.internal_data = {}
76 host.trigger.add("sendMessage", self.sendMessageTrigger, TriggerManager.MIN_PRIORITY) 75 host.trigger.add("sendMessage", self.sendMessageTrigger, TriggerManager.MIN_PRIORITY)
77 host.trigger.add("MessageReceived", self.messageReceivedTrigger) 76 host.trigger.add("MessageReceived", self.messageReceivedTrigger)
78 77
85 84
86 def discoCallback(entity): 85 def discoCallback(entity):
87 if entity is None: 86 if entity is None:
88 return Failure(AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!"))) 87 return Failure(AbortSendMessage(_("XEP-0033 is being used but the server doesn't support it!")))
89 if mess_data["to"] != entity: 88 if mess_data["to"] != entity:
90 logging.warning(_("Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!") % {'expected': entity, 'current': mess_data["to"]}) 89 log.warning(_("Stanzas using XEP-0033 should be addressed to %(expected)s, not %(current)s!") % {'expected': entity, 'current': mess_data["to"]})
91 logging.warning(_("TODO: addressing has be fixed by the backend... fix it in the frontend!")) 90 log.warning(_("TODO: addressing has be fixed by the backend... fix it in the frontend!"))
92 mess_data["to"] = entity 91 mess_data["to"] = entity
93 element = mess_data['xml'].addElement('addresses', NS_ADDRESS) 92 element = mess_data['xml'].addElement('addresses', NS_ADDRESS)
94 entries = [entry.split(':') for entry in mess_data['extra']['address'].split('\n') if entry != ''] 93 entries = [entry.split(':') for entry in mess_data['extra']['address'].split('\n') if entry != '']
95 for type_, jid_ in entries: 94 for type_, jid_ in entries:
96 element.addChild(domish.Element((None, 'address'), None, {'type': type_, 'jid': jid_})) 95 element.addChild(domish.Element((None, 'address'), None, {'type': type_, 'jid': jid_}))