From 363ee1db88bb567528b1dc08e426838f0f28aa91 Mon Sep 17 00:00:00 2001 From: Goffi Date: Fri, 20 Oct 2017 08:44:09 +0200 Subject: [PATCH] plugin XEP-0060: added createIfNewNode method which doesn't fail in case of conflict. --- src/plugins/plugin_xep_0060.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/plugins/plugin_xep_0060.py b/src/plugins/plugin_xep_0060.py index f91899b2..df850603 100755 --- a/src/plugins/plugin_xep_0060.py +++ b/src/plugins/plugin_xep_0060.py @@ -447,6 +447,17 @@ class XEP_0060(object): """ return client.pubsub_client.createNode(service, nodeIdentifier, options) + @defer.inlineCallbacks + def createIfNewNode(self, client, service, nodeIdentifier, options=None): + """Helper method similar to createNode, but will not fail in case of conflict""" + try: + yield self.createNode(client, service, nodeIdentifier, options) + except error.StanzaError as e: + if e.condition == 'conflict': + pass + else: + raise e + def _getNodeConfiguration(self, service_s, nodeIdentifier, profile_key): client = self.host.getClient(profile_key) d = self.getConfiguration(client, jid.JID(service_s) if service_s else None, nodeIdentifier)