comparison sat/plugins/plugin_xep_0060.py @ 3899:1e64f1ed3ebd

plugin XEP-0060: raise an `NotFound` exception instead of StanzaError in `subscribe`: `exceptions.NotFound` is now raised in stead of `item-not-found` `StanzaError` for consistency with `getItems` and because it's easier to catch (condition has to be checked when `StanzaError` is received). rel 372
author Goffi <goffi@goffi.org>
date Wed, 21 Sep 2022 22:32:36 +0200
parents c3e6c54660da
children 8289ac1b34f4
comparison
equal deleted inserted replaced
3898:022ae35a9d82 3899:1e64f1ed3ebd
1205 cont, trigger_sub = await self.host.trigger.asyncReturnPoint( 1205 cont, trigger_sub = await self.host.trigger.asyncReturnPoint(
1206 "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options, 1206 "XEP-0060_subscribe", client, service, nodeIdentifier, sub_jid, options,
1207 ) 1207 )
1208 if not cont: 1208 if not cont:
1209 return trigger_sub 1209 return trigger_sub
1210 subscription = await client.pubsub_client.subscribe( 1210 try:
1211 service, nodeIdentifier, sub_jid or client.jid.userhostJID(), options=options, 1211 subscription = await client.pubsub_client.subscribe(
1212 sender=client.jid.userhostJID() 1212 service, nodeIdentifier, sub_jid or client.jid.userhostJID(),
1213 ) 1213 options=options, sender=client.jid.userhostJID()
1214 )
1215 except error.StanzaError as e:
1216 if e.condition == 'item-not-found':
1217 raise exceptions.NotFound(e.text or e.condition)
1218 else:
1219 raise e
1214 return subscription 1220 return subscription
1215 1221
1216 def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE): 1222 def _unsubscribe(self, service, nodeIdentifier, profile_key=C.PROF_KEY_NONE):
1217 client = self.host.getClient(profile_key) 1223 client = self.host.getClient(profile_key)
1218 service = None if not service else jid.JID(service) 1224 service = None if not service else jid.JID(service)