Mercurial > libervia-backend
comparison sat/plugins/plugin_xep_0352.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 | 0c54970d8e6e |
children | 9d0df638c8b4 |
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 Explicit Message Encryption | 4 # SAT plugin for Explicit Message Encryption |
5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
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 | 26 |
27 PLUGIN_INFO = { | 27 PLUGIN_INFO = { |
28 C.PI_NAME: u"Client State Indication", | 28 C.PI_NAME: "Client State Indication", |
29 C.PI_IMPORT_NAME: u"XEP-0352", | 29 C.PI_IMPORT_NAME: "XEP-0352", |
30 C.PI_TYPE: C.PLUG_TYPE_XEP, | 30 C.PI_TYPE: C.PLUG_TYPE_XEP, |
31 C.PI_PROTOCOLS: [u"XEP-0352"], | 31 C.PI_PROTOCOLS: ["XEP-0352"], |
32 C.PI_DEPENDENCIES: [], | 32 C.PI_DEPENDENCIES: [], |
33 C.PI_MAIN: u"XEP_0352", | 33 C.PI_MAIN: "XEP_0352", |
34 C.PI_HANDLER: u"no", | 34 C.PI_HANDLER: "no", |
35 C.PI_DESCRIPTION: D_(u"Notify server when frontend is not actively used, to limit " | 35 C.PI_DESCRIPTION: D_("Notify server when frontend is not actively used, to limit " |
36 u"traffic and save bandwidth and battery life"), | 36 "traffic and save bandwidth and battery life"), |
37 } | 37 } |
38 | 38 |
39 NS_CSI = u"urn:xmpp:csi:0" | 39 NS_CSI = "urn:xmpp:csi:0" |
40 | 40 |
41 | 41 |
42 class XEP_0352(object): | 42 class XEP_0352(object): |
43 | 43 |
44 def __init__(self, host): | 44 def __init__(self, host): |
45 log.info(_(u"Client State Indication plugin initialization")) | 45 log.info(_("Client State Indication plugin initialization")) |
46 self.host = host | 46 self.host = host |
47 host.registerNamespace(u"csi", NS_CSI) | 47 host.registerNamespace("csi", NS_CSI) |
48 | 48 |
49 def isActive(self, client): | 49 def isActive(self, client): |
50 try: | 50 try: |
51 if not client._xep_0352_enabled: | 51 if not client._xep_0352_enabled: |
52 return True | 52 return True |
53 return client._xep_0352_active | 53 return client._xep_0352_active |
54 except AttributeError: | 54 except AttributeError: |
55 # _xep_0352_active can not be set if isActive is called before | 55 # _xep_0352_active can not be set if isActive is called before |
56 # profileConnected has been called | 56 # profileConnected has been called |
57 log.debug(u"isActive called when XEP-0352 plugin has not yet set the " | 57 log.debug("isActive called when XEP-0352 plugin has not yet set the " |
58 u"attributes") | 58 "attributes") |
59 return True | 59 return True |
60 | 60 |
61 def profileConnected(self, client): | 61 def profileConnected(self, client): |
62 if (NS_CSI, u'csi') in client.xmlstream.features: | 62 if (NS_CSI, 'csi') in client.xmlstream.features: |
63 log.info(_(u"Client State Indication is available on this server")) | 63 log.info(_("Client State Indication is available on this server")) |
64 client._xep_0352_enabled = True | 64 client._xep_0352_enabled = True |
65 client._xep_0352_active = True | 65 client._xep_0352_active = True |
66 else: | 66 else: |
67 log.warning(_(u"Client State Indication is not available on this server, some" | 67 log.warning(_("Client State Indication is not available on this server, some" |
68 u" bandwidth optimisations can't be used.")) | 68 " bandwidth optimisations can't be used.")) |
69 client._xep_0352_enabled = False | 69 client._xep_0352_enabled = False |
70 | 70 |
71 def setInactive(self, client): | 71 def setInactive(self, client): |
72 if self.isActive(client): | 72 if self.isActive(client): |
73 inactive_elt = domish.Element((NS_CSI, u'inactive')) | 73 inactive_elt = domish.Element((NS_CSI, 'inactive')) |
74 client.send(inactive_elt) | 74 client.send(inactive_elt) |
75 client._xep_0352_active = False | 75 client._xep_0352_active = False |
76 log.info(u"inactive state set") | 76 log.info("inactive state set") |
77 | 77 |
78 def setActive(self, client): | 78 def setActive(self, client): |
79 if not self.isActive(client): | 79 if not self.isActive(client): |
80 active_elt = domish.Element((NS_CSI, u'active')) | 80 active_elt = domish.Element((NS_CSI, 'active')) |
81 client.send(active_elt) | 81 client.send(active_elt) |
82 client._xep_0352_active = True | 82 client._xep_0352_active = True |
83 log.info(u"active state set") | 83 log.info("active state set") |