comparison sat/plugins/plugin_exp_pubsub_admin.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 838f53730ce4
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 to send pubsub requests with administrator privilege 4 # SAT plugin to send pubsub requests with administrator privilege
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
27 from wokkel import generic 27 from wokkel import generic
28 28
29 log = getLogger(__name__) 29 log = getLogger(__name__)
30 30
31 PLUGIN_INFO = { 31 PLUGIN_INFO = {
32 C.PI_NAME: u"Pubsub Administrator", 32 C.PI_NAME: "Pubsub Administrator",
33 C.PI_IMPORT_NAME: u"PUBSUB_ADMIN", 33 C.PI_IMPORT_NAME: "PUBSUB_ADMIN",
34 C.PI_TYPE: C.PLUG_TYPE_EXP, 34 C.PI_TYPE: C.PLUG_TYPE_EXP,
35 C.PI_PROTOCOLS: [], 35 C.PI_PROTOCOLS: [],
36 C.PI_DEPENDENCIES: [], 36 C.PI_DEPENDENCIES: [],
37 C.PI_RECOMMENDATIONS: [], 37 C.PI_RECOMMENDATIONS: [],
38 C.PI_MAIN: u"PubsubAdmin", 38 C.PI_MAIN: "PubsubAdmin",
39 C.PI_HANDLER: u"no", 39 C.PI_HANDLER: "no",
40 C.PI_DESCRIPTION: _(u"""\Implementation of Pubsub Administrator 40 C.PI_DESCRIPTION: _("""\Implementation of Pubsub Administrator
41 This allows a pubsub administrator to overwrite completly items, including publisher. 41 This allows a pubsub administrator to overwrite completly items, including publisher.
42 Specially useful when importing a node."""), 42 Specially useful when importing a node."""),
43 } 43 }
44 44
45 NS_PUBSUB_ADMIN = u"https://salut-a-toi.org/spec/pubsub_admin:0" 45 NS_PUBSUB_ADMIN = "https://salut-a-toi.org/spec/pubsub_admin:0"
46 46
47 47
48 class PubsubAdmin(object): 48 class PubsubAdmin(object):
49 49
50 def __init__(self, host): 50 def __init__(self, host):
53 "psAdminItemsSend", 53 "psAdminItemsSend",
54 ".plugin", 54 ".plugin",
55 in_sign="ssasss", 55 in_sign="ssasss",
56 out_sign="as", 56 out_sign="as",
57 method=self._publish, 57 method=self._publish,
58 async=True, 58 async_=True,
59 ) 59 )
60 60
61 def _publish(self, service, nodeIdentifier, items, extra=None, 61 def _publish(self, service, nodeIdentifier, items, extra=None,
62 profile_key=C.PROF_KEY_NONE): 62 profile_key=C.PROF_KEY_NONE):
63 client = self.host.getClient(profile_key) 63 client = self.host.getClient(profile_key)
69 ) 69 )
70 70
71 def _sendCb(self, iq_result): 71 def _sendCb(self, iq_result):
72 publish_elt = iq_result.admin.pubsub.publish 72 publish_elt = iq_result.admin.pubsub.publish
73 ids = [] 73 ids = []
74 for item_elt in publish_elt.elements(pubsub.NS_PUBSUB, u'item'): 74 for item_elt in publish_elt.elements(pubsub.NS_PUBSUB, 'item'):
75 ids.append(item_elt[u'id']) 75 ids.append(item_elt['id'])
76 return ids 76 return ids
77 77
78 def publish(self, client, service, nodeIdentifier, items, extra=None): 78 def publish(self, client, service, nodeIdentifier, items, extra=None):
79 for item in items: 79 for item in items:
80 if item.name != u'item' or item.uri != pubsub.NS_PUBSUB: 80 if item.name != 'item' or item.uri != pubsub.NS_PUBSUB:
81 raise exceptions.DataError( 81 raise exceptions.DataError(
82 u'Invalid element, a pubsub item is expected: {xml}'.format( 82 'Invalid element, a pubsub item is expected: {xml}'.format(
83 xml=item.toXml())) 83 xml=item.toXml()))
84 iq_elt = client.IQ() 84 iq_elt = client.IQ()
85 iq_elt['to'] = service.full() if service else client.jid.userhost() 85 iq_elt['to'] = service.full() if service else client.jid.userhost()
86 admin_elt = iq_elt.addElement((NS_PUBSUB_ADMIN, u'admin')) 86 admin_elt = iq_elt.addElement((NS_PUBSUB_ADMIN, 'admin'))
87 pubsub_elt = admin_elt.addElement((pubsub.NS_PUBSUB, u'pubsub')) 87 pubsub_elt = admin_elt.addElement((pubsub.NS_PUBSUB, 'pubsub'))
88 publish_elt = pubsub_elt.addElement('publish') 88 publish_elt = pubsub_elt.addElement('publish')
89 publish_elt[u'node'] = nodeIdentifier 89 publish_elt['node'] = nodeIdentifier
90 for item in items: 90 for item in items:
91 publish_elt.addChild(item) 91 publish_elt.addChild(item)
92 d = iq_elt.send() 92 d = iq_elt.send()
93 d.addCallback(self._sendCb) 93 d.addCallback(self._sendCb)
94 return d 94 return d