Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0085.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 94708a7d3ecf |
children | 559a625a236b |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SAT plugin for Chat State Notifications Protocol (xep-0085) | 4 # SAT plugin for Chat State Notifications Protocol (xep-0085) |
5 # Copyright (C) 2009-2016 Adrien Cossa (souliane@mailoo.org) | 5 # Copyright (C) 2009-2016 Adrien Cossa (souliane@mailoo.org) |
6 | 6 |
22 from sat.core import exceptions | 22 from sat.core import exceptions |
23 from sat.core.log import getLogger | 23 from sat.core.log import getLogger |
24 | 24 |
25 log = getLogger(__name__) | 25 log = getLogger(__name__) |
26 from wokkel import disco, iwokkel | 26 from wokkel import disco, iwokkel |
27 from zope.interface import implements | 27 from zope.interface import implementer |
28 from twisted.words.protocols.jabber.jid import JID | 28 from twisted.words.protocols.jabber.jid import JID |
29 | 29 |
30 try: | 30 try: |
31 from twisted.words.protocols.xmlstream import XMPPHandler | 31 from twisted.words.protocols.xmlstream import XMPPHandler |
32 except ImportError: | 32 except ImportError: |
183 if self._isMUC(from_jid, profile): | 183 if self._isMUC(from_jid, profile): |
184 from_jid = from_jid.userhostJID() | 184 from_jid = from_jid.userhostJID() |
185 else: # update entity data for one2one chat | 185 else: # update entity data for one2one chat |
186 # assert from_jid.resource # FIXME: assert doesn't work on normal message from server (e.g. server announce), because there is no resource | 186 # assert from_jid.resource # FIXME: assert doesn't work on normal message from server (e.g. server announce), because there is no resource |
187 try: | 187 try: |
188 domish.generateElementsNamed(message.elements(), name="body").next() | 188 next(domish.generateElementsNamed(message.elements(), name="body")) |
189 try: | 189 try: |
190 domish.generateElementsNamed(message.elements(), name="active").next() | 190 next(domish.generateElementsNamed(message.elements(), name="active")) |
191 # contact enabled Chat State Notifications | 191 # contact enabled Chat State Notifications |
192 self.updateCache(from_jid, True, profile=profile) | 192 self.updateCache(from_jid, True, profile=profile) |
193 except StopIteration: | 193 except StopIteration: |
194 if message.getAttribute("type") == "chat": | 194 if message.getAttribute("type") == "chat": |
195 # contact didn't enable Chat State Notifications | 195 # contact didn't enable Chat State Notifications |
231 to_jid = JID(message.getAttribute("to")) | 231 to_jid = JID(message.getAttribute("to")) |
232 if not self._checkActivation(to_jid, forceEntityData=True, profile=profile): | 232 if not self._checkActivation(to_jid, forceEntityData=True, profile=profile): |
233 return mess_data | 233 return mess_data |
234 try: | 234 try: |
235 # message with a body always mean active state | 235 # message with a body always mean active state |
236 domish.generateElementsNamed(message.elements(), name="body").next() | 236 next(domish.generateElementsNamed(message.elements(), name="body")) |
237 message.addElement("active", NS_CHAT_STATES) | 237 message.addElement("active", NS_CHAT_STATES) |
238 # launch the chat state machine (init the timer) | 238 # launch the chat state machine (init the timer) |
239 if self._isMUC(to_jid, profile): | 239 if self._isMUC(to_jid, profile): |
240 to_jid = to_jid.userhostJID() | 240 to_jid = to_jid.userhostJID() |
241 self._chatStateActive(to_jid, mess_data["type"], profile) | 241 self._chatStateActive(to_jid, mess_data["type"], profile) |
383 | 383 |
384 if state != self.state and state != "active": | 384 if state != self.state and state != "active": |
385 if state != "gone" or self.mess_type != "groupchat": | 385 if state != "gone" or self.mess_type != "groupchat": |
386 # send a new message without body | 386 # send a new message without body |
387 log.debug( | 387 log.debug( |
388 u"sending state '{state}' to {jid}".format( | 388 "sending state '{state}' to {jid}".format( |
389 state=state, jid=self.to_jid.full() | 389 state=state, jid=self.to_jid.full() |
390 ) | 390 ) |
391 ) | 391 ) |
392 client = self.host.getClient(self.profile) | 392 client = self.host.getClient(self.profile) |
393 mess_data = { | 393 mess_data = { |
413 self.timer = reactor.callLater( | 413 self.timer = reactor.callLater( |
414 transition["delay"], self._onEvent, transition["next_state"] | 414 transition["delay"], self._onEvent, transition["next_state"] |
415 ) | 415 ) |
416 | 416 |
417 | 417 |
418 @implementer(iwokkel.IDisco) | |
418 class XEP_0085_handler(XMPPHandler): | 419 class XEP_0085_handler(XMPPHandler): |
419 implements(iwokkel.IDisco) | |
420 | 420 |
421 def __init__(self, plugin_parent, profile): | 421 def __init__(self, plugin_parent, profile): |
422 self.plugin_parent = plugin_parent | 422 self.plugin_parent = plugin_parent |
423 self.host = plugin_parent.host | 423 self.host = plugin_parent.host |
424 self.profile = profile | 424 self.profile = profile |