comparison sat/plugins/plugin_xep_0100.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 003b8b4b56a7
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 managing gateways (xep-0100) 4 # SAT plugin for managing gateways (xep-0100)
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
36 C.PI_MAIN: "XEP_0100", 36 C.PI_MAIN: "XEP_0100",
37 C.PI_DESCRIPTION: _("""Implementation of Gateways protocol"""), 37 C.PI_DESCRIPTION: _("""Implementation of Gateways protocol"""),
38 } 38 }
39 39
40 WARNING_MSG = D_( 40 WARNING_MSG = D_(
41 u"""Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as XMPP contacts. 41 """Be careful ! Gateways allow you to use an external IM (legacy IM), so you can see your contact as XMPP contacts.
42 But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analysed by the external server, most of time a private company).""" 42 But when you do this, all your messages go throught the external legacy IM server, it is a huge privacy issue (i.e.: all your messages throught the gateway can be monitored, recorded, analysed by the external server, most of time a private company)."""
43 ) 43 )
44 44
45 GATEWAY_TIMEOUT = 10 # time to wait before cancelling a gateway disco info, in seconds 45 GATEWAY_TIMEOUT = 10 # time to wait before cancelling a gateway disco info, in seconds
46 46
131 adv_list.end() 131 adv_list.end()
132 xmlui.addDivider("blank") 132 xmlui.addDivider("blank")
133 xmlui.changeContainer("advanced_list", columns=3) 133 xmlui.changeContainer("advanced_list", columns=3)
134 xmlui.addLabel(_("Use external XMPP server")) 134 xmlui.addLabel(_("Use external XMPP server"))
135 xmlui.addString("external_jid") 135 xmlui.addString("external_jid")
136 xmlui.addButton(self.__menu_id, _(u"Go !"), fields_back=("external_jid",)) 136 xmlui.addButton(self.__menu_id, _("Go !"), fields_back=("external_jid",))
137 return xmlui 137 return xmlui
138 138
139 def _gatewaySelectedCb(self, data, profile): 139 def _gatewaySelectedCb(self, data, profile):
140 try: 140 try:
141 target_jid = jid.JID(data["index"]) 141 target_jid = jid.JID(data["index"])
154 """ 154 """
155 category, type_ = identity 155 category, type_ = identity
156 if category != "gateway": 156 if category != "gateway":
157 log.error( 157 log.error(
158 _( 158 _(
159 u'INTERNAL ERROR: identity category should always be "gateway" in _getTypeString, got "%s"' 159 'INTERNAL ERROR: identity category should always be "gateway" in _getTypeString, got "%s"'
160 ) 160 )
161 % category 161 % category
162 ) 162 )
163 try: 163 try:
164 return _(TYPE_DESCRIPTIONS[type_]) 164 return _(TYPE_DESCRIPTIONS[type_])
206 for identity in result.identities 206 for identity in result.identities
207 if identity[0] == "gateway" 207 if identity[0] == "gateway"
208 ] 208 ]
209 if gateways: 209 if gateways:
210 log.info( 210 log.info(
211 _(u"Found gateway [%(jid)s]: %(identity_name)s") 211 _("Found gateway [%(jid)s]: %(identity_name)s")
212 % { 212 % {
213 "jid": entity.full(), 213 "jid": entity.full(),
214 "identity_name": " - ".join( 214 "identity_name": " - ".join(
215 [gateway[1] for gateway in gateways] 215 [gateway[1] for gateway in gateways]
216 ), 216 ),
217 } 217 }
218 ) 218 )
219 ret.append((success, (entity, gateways))) 219 ret.append((success, (entity, gateways)))
220 else: 220 else:
221 log.info( 221 log.info(
222 _(u"Skipping [%(jid)s] which is not a gateway") 222 _("Skipping [%(jid)s] which is not a gateway")
223 % {"jid": entity.full()} 223 % {"jid": entity.full()}
224 ) 224 )
225 return ret 225 return ret
226 226
227 def _itemsReceived(self, disco, target, client): 227 def _itemsReceived(self, disco, target, client):
231 log.debug(_("No gateway found")) 231 log.debug(_("No gateway found"))
232 return [] 232 return []
233 233
234 _defers = [] 234 _defers = []
235 for item in disco._items: 235 for item in disco._items:
236 log.debug(_(u"item found: %s") % item.entity) 236 log.debug(_("item found: %s") % item.entity)
237 _defers.append(client.disco.requestInfo(item.entity)) 237 _defers.append(client.disco.requestInfo(item.entity))
238 dl = defer.DeferredList(_defers) 238 dl = defer.DeferredList(_defers)
239 dl.addCallback( 239 dl.addCallback(
240 self._infosReceived, items=disco._items, target=target, client=client 240 self._infosReceived, items=disco._items, target=target, client=client
241 ) 241 )
255 def findGateways(self, target, profile): 255 def findGateways(self, target, profile):
256 """Find gateways in the target JID, using discovery protocol 256 """Find gateways in the target JID, using discovery protocol
257 """ 257 """
258 client = self.host.getClient(profile) 258 client = self.host.getClient(profile)
259 log.debug( 259 log.debug(
260 _(u"find gateways (target = %(target)s, profile = %(profile)s)") 260 _("find gateways (target = %(target)s, profile = %(profile)s)")
261 % {"target": target.full(), "profile": profile} 261 % {"target": target.full(), "profile": profile}
262 ) 262 )
263 d = client.disco.requestItems(target) 263 d = client.disco.requestItems(target)
264 d.addCallback(self._itemsReceived, target=target, client=client) 264 d.addCallback(self._itemsReceived, target=target, client=client)
265 return d 265 return d