Reformatted code base using black.
This commit is contained in:
parent
56319cbad3
commit
53fdaa9d09
1 changed files with 12604 additions and 8966 deletions
|
|
@ -37,9 +37,11 @@ PLUGIN_INFO = {
|
|||
C.PI_RECOMMENDATIONS: [],
|
||||
C.PI_MAIN: "PubsubAdmin",
|
||||
C.PI_HANDLER: "no",
|
||||
C.PI_DESCRIPTION: _("""\Implementation of Pubsub Administrator
|
||||
C.PI_DESCRIPTION: _(
|
||||
"""\Implementation of Pubsub Administrator
|
||||
This allows a pubsub administrator to overwrite completly items, including publisher.
|
||||
Specially useful when importing a node."""),
|
||||
Specially useful when importing a node."""
|
||||
),
|
||||
}
|
||||
|
||||
NS_PUBSUB_ADMIN = "https://salut-a-toi.org/spec/pubsub_admin:0"
|
||||
|
|
@ -58,35 +60,36 @@ class PubsubAdmin(object):
|
|||
async_=True,
|
||||
)
|
||||
|
||||
def _publish(self, service, nodeIdentifier, items, extra=None,
|
||||
profile_key=C.PROF_KEY_NONE):
|
||||
def _publish(
|
||||
self, service, nodeIdentifier, items, extra=None, profile_key=C.PROF_KEY_NONE
|
||||
):
|
||||
client = self.host.get_client(profile_key)
|
||||
service = None if not service else jid.JID(service)
|
||||
extra = data_format.deserialise(extra)
|
||||
items = [generic.parseXml(i.encode('utf-8')) for i in items]
|
||||
return self.publish(
|
||||
client, service, nodeIdentifier, items, extra
|
||||
)
|
||||
items = [generic.parseXml(i.encode("utf-8")) for i in items]
|
||||
return self.publish(client, service, nodeIdentifier, items, extra)
|
||||
|
||||
def _send_cb(self, iq_result):
|
||||
publish_elt = iq_result.admin.pubsub.publish
|
||||
ids = []
|
||||
for item_elt in publish_elt.elements(pubsub.NS_PUBSUB, 'item'):
|
||||
ids.append(item_elt['id'])
|
||||
for item_elt in publish_elt.elements(pubsub.NS_PUBSUB, "item"):
|
||||
ids.append(item_elt["id"])
|
||||
return ids
|
||||
|
||||
def publish(self, client, service, nodeIdentifier, items, extra=None):
|
||||
for item in items:
|
||||
if item.name != 'item' or item.uri != pubsub.NS_PUBSUB:
|
||||
if item.name != "item" or item.uri != pubsub.NS_PUBSUB:
|
||||
raise exceptions.DataError(
|
||||
'Invalid element, a pubsub item is expected: {xml}'.format(
|
||||
xml=item.toXml()))
|
||||
"Invalid element, a pubsub item is expected: {xml}".format(
|
||||
xml=item.toXml()
|
||||
)
|
||||
)
|
||||
iq_elt = client.IQ()
|
||||
iq_elt['to'] = service.full() if service else client.jid.userhost()
|
||||
admin_elt = iq_elt.addElement((NS_PUBSUB_ADMIN, 'admin'))
|
||||
pubsub_elt = admin_elt.addElement((pubsub.NS_PUBSUB, 'pubsub'))
|
||||
publish_elt = pubsub_elt.addElement('publish')
|
||||
publish_elt['node'] = nodeIdentifier
|
||||
iq_elt["to"] = service.full() if service else client.jid.userhost()
|
||||
admin_elt = iq_elt.addElement((NS_PUBSUB_ADMIN, "admin"))
|
||||
pubsub_elt = admin_elt.addElement((pubsub.NS_PUBSUB, "pubsub"))
|
||||
publish_elt = pubsub_elt.addElement("publish")
|
||||
publish_elt["node"] = nodeIdentifier
|
||||
for item in items:
|
||||
publish_elt.addChild(item)
|
||||
d = iq_elt.send()
|
||||
|
|
|
|||
Loading…
Reference in a new issue