Mercurial > sat_tmp
changeset 86:636d48c2b77a
wokkel (pubsub): fix subscriptions node and unsubscribe response element:
- `subscriptions` was incorrectly using `nodeOrEmpty`, while node can be omitted, thus
`nodeOrNone` is now used.
- fix missing `<subscription>` element in `unsubscribe` response
- typing
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 11 May 2022 13:13:32 +0200 |
parents | ba3f695fff34 |
children | 42cb377e3f3e |
files | sat_tmp/wokkel/pubsub.py |
diffstat | 1 files changed, 114 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- a/sat_tmp/wokkel/pubsub.py Tue Jan 25 18:53:37 2022 +0100 +++ b/sat_tmp/wokkel/pubsub.py Wed May 11 13:13:32 2022 +0200 @@ -56,6 +56,7 @@ U{XEP-0060<http://xmpp.org/extensions/xep-0060.html>}. """ +from typing import Optional from zope.interface import implementer from twisted.internet import defer @@ -336,7 +337,7 @@ 'unsubscribe': ['nodeOrEmpty', 'jid', 'subidOrNone'], 'optionsGet': ['nodeOrEmpty', 'jid', 'subidOrNone'], 'optionsSet': ['nodeOrEmpty', 'jid', 'options', 'subidOrNone'], - 'subscriptions': ['nodeOrEmpty'], + 'subscriptions': ['nodeOrNone'], 'affiliations': ['nodeOrNone'], 'create': ['nodeOrNone', 'configureOrNone'], 'default': ['default'], @@ -1218,6 +1219,99 @@ return d +@implementer(IPubSubResource) +class PubSubResource(object): + + + features = [] + discoIdentity = disco.DiscoIdentity('pubsub', + 'service', + 'Publish-Subscribe Service') + + + def locateResource(self, request): + return self + + + def getInfo(self, requestor, service, nodeIdentifier): + return defer.succeed(None) + + + def getNodes(self, requestor, service, nodeIdentifier): + return defer.succeed([]) + + + def getConfigurationOptions(self): + return {} + + + def publish(self, request): + return defer.fail(Unsupported('publish')) + + + def subscribe(self, request): + return defer.fail(Unsupported('subscribe')) + + + def unsubscribe(self, request): + return defer.fail(Unsupported('subscribe')) + + + def subscriptions(self, request): + return defer.fail(Unsupported('retrieve-subscriptions')) + + + def affiliations(self, request): + return defer.fail(Unsupported('retrieve-affiliations')) + + + def create(self, request): + return defer.fail(Unsupported('create-nodes')) + + + def default(self, request): + return defer.fail(Unsupported('retrieve-default')) + + + def configureGet(self, request): + return defer.fail(Unsupported('config-node')) + + + def configureSet(self, request): + return defer.fail(Unsupported('config-node')) + + + def items(self, request): + return defer.fail(Unsupported('retrieve-items')) + + + def retract(self, request): + return defer.fail(Unsupported('retract-items')) + + + def purge(self, request): + return defer.fail(Unsupported('purge-nodes')) + + + def delete(self, request): + return defer.fail(Unsupported('delete-nodes')) + + + def affiliationsGet(self, request): + return defer.fail(Unsupported('retrieve-affiliations')) + + + def affiliationsSet(self, request): + return defer.fail(Unsupported('modify-affiliations')) + + + def subscriptionsGet(self, request): + return defer.fail(Unsupported('manage-subscriptions')) + + + def subscriptionsSet(self, request): + return defer.fail(Unsupported('manage-subscriptions')) + @implementer(IPubSubService, disco.IDisco) class PubSubService(XMPPHandler, IQHandlerMixin): @@ -1433,12 +1527,30 @@ return d - def _toResponse_subscribe(self, result, resource, request): + def _toResponse_subscribe( + self, + result: Subscription, + resource: PubSubResource, + request: PubSubRequest + ) -> domish.Element: response = domish.Element((NS_PUBSUB, "pubsub")) response.addChild(result.toElement(NS_PUBSUB)) return response + def _toResponse_unsubscribe( + self, + result: Optional[Subscription], + resource: PubSubResource, + request: PubSubRequest + ) -> domish.Element: + response = domish.Element((NS_PUBSUB, "pubsub")) + if result is None: + result = Subscription(request.nodeIdentifier, request.subscriber, "none") + response.addChild(result.toElement(NS_PUBSUB)) + return response + + def _toResponse_subscriptions(self, result, resource, request): response = domish.Element((NS_PUBSUB, 'pubsub')) subscriptions = response.addElement('subscriptions') @@ -1695,95 +1807,3 @@ -@implementer(IPubSubResource) -class PubSubResource(object): - - - features = [] - discoIdentity = disco.DiscoIdentity('pubsub', - 'service', - 'Publish-Subscribe Service') - - - def locateResource(self, request): - return self - - - def getInfo(self, requestor, service, nodeIdentifier): - return defer.succeed(None) - - - def getNodes(self, requestor, service, nodeIdentifier): - return defer.succeed([]) - - - def getConfigurationOptions(self): - return {} - - - def publish(self, request): - return defer.fail(Unsupported('publish')) - - - def subscribe(self, request): - return defer.fail(Unsupported('subscribe')) - - - def unsubscribe(self, request): - return defer.fail(Unsupported('subscribe')) - - - def subscriptions(self, request): - return defer.fail(Unsupported('retrieve-subscriptions')) - - - def affiliations(self, request): - return defer.fail(Unsupported('retrieve-affiliations')) - - - def create(self, request): - return defer.fail(Unsupported('create-nodes')) - - - def default(self, request): - return defer.fail(Unsupported('retrieve-default')) - - - def configureGet(self, request): - return defer.fail(Unsupported('config-node')) - - - def configureSet(self, request): - return defer.fail(Unsupported('config-node')) - - - def items(self, request): - return defer.fail(Unsupported('retrieve-items')) - - - def retract(self, request): - return defer.fail(Unsupported('retract-items')) - - - def purge(self, request): - return defer.fail(Unsupported('purge-nodes')) - - - def delete(self, request): - return defer.fail(Unsupported('delete-nodes')) - - - def affiliationsGet(self, request): - return defer.fail(Unsupported('retrieve-affiliations')) - - - def affiliationsSet(self, request): - return defer.fail(Unsupported('modify-affiliations')) - - - def subscriptionsGet(self, request): - return defer.fail(Unsupported('manage-subscriptions')) - - - def subscriptionsSet(self, request): - return defer.fail(Unsupported('manage-subscriptions'))