Mercurial > libervia-backend
comparison src/tmp/wokkel/pubsub.py @ 1457:2e43eb9d8167
tmp(pubsub): added retract "notify" attribute management
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 16 Aug 2015 00:06:12 +0200 |
parents | 2d8fccec84e8 |
children | 91631837ce5c |
comparison
equal
deleted
inserted
replaced
1456:a13be5c22334 | 1457:2e43eb9d8167 |
---|---|
84 # XPath to match pubsub requests | 84 # XPath to match pubsub requests |
85 PUBSUB_REQUEST = '/iq[@type="get" or @type="set"]/' + \ | 85 PUBSUB_REQUEST = '/iq[@type="get" or @type="set"]/' + \ |
86 'pubsub[@xmlns="' + NS_PUBSUB + '" or ' + \ | 86 'pubsub[@xmlns="' + NS_PUBSUB + '" or ' + \ |
87 '@xmlns="' + NS_PUBSUB_OWNER + '"]' | 87 '@xmlns="' + NS_PUBSUB_OWNER + '"]' |
88 | 88 |
89 BOOL_TRUE = ('1','true') | |
90 BOOL_FALSE = ('0','false') | |
91 | |
89 class SubscriptionPending(Exception): | 92 class SubscriptionPending(Exception): |
90 """ | 93 """ |
91 Raised when the requested subscription is pending acceptance. | 94 Raised when the requested subscription is pending acceptance. |
92 """ | 95 """ |
93 | 96 |
293 options = None | 296 options = None |
294 subscriber = None | 297 subscriber = None |
295 subscriptionIdentifier = None | 298 subscriptionIdentifier = None |
296 subscriptions = None | 299 subscriptions = None |
297 affiliations = None | 300 affiliations = None |
301 notify = None | |
298 | 302 |
299 # Map request iq type and subelement name to request verb | 303 # Map request iq type and subelement name to request verb |
300 _requestVerbMap = { | 304 _requestVerbMap = { |
301 ('set', NS_PUBSUB, 'publish'): 'publish', | 305 ('set', NS_PUBSUB, 'publish'): 'publish', |
302 ('set', NS_PUBSUB, 'subscribe'): 'subscribe', | 306 ('set', NS_PUBSUB, 'subscribe'): 'subscribe', |
334 'create': ['nodeOrNone', 'configureOrNone'], | 338 'create': ['nodeOrNone', 'configureOrNone'], |
335 'default': ['default'], | 339 'default': ['default'], |
336 'configureGet': ['nodeOrEmpty'], | 340 'configureGet': ['nodeOrEmpty'], |
337 'configureSet': ['nodeOrEmpty', 'configure'], | 341 'configureSet': ['nodeOrEmpty', 'configure'], |
338 'items': ['node', 'maxItems', 'itemIdentifiers', 'subidOrNone'], | 342 'items': ['node', 'maxItems', 'itemIdentifiers', 'subidOrNone'], |
339 'retract': ['node', 'itemIdentifiers'], | 343 'retract': ['node', 'notify', 'itemIdentifiers'], |
340 'purge': ['node'], | 344 'purge': ['node'], |
341 'delete': ['node'], | 345 'delete': ['node'], |
342 'affiliationsGet': ['nodeOrEmpty'], | 346 'affiliationsGet': ['nodeOrEmpty'], |
343 'affiliationsSet': ['nodeOrEmpty', 'affiliations'], | 347 'affiliationsSet': ['nodeOrEmpty', 'affiliations'], |
344 'subscriptionsGet': ['nodeOrEmpty'], | 348 'subscriptionsGet': ['nodeOrEmpty'], |
607 raise BadRequest(text='Missing affiliation attribute') | 611 raise BadRequest(text='Missing affiliation attribute') |
608 | 612 |
609 self.affiliations[entity] = affiliation | 613 self.affiliations[entity] = affiliation |
610 | 614 |
611 | 615 |
616 def _parse_notify(self, verbElement): | |
617 value = verbElement.getAttribute('notify') | |
618 | |
619 if value: | |
620 if value in BOOL_TRUE: | |
621 self.notify = True | |
622 elif value in BOOL_FALSE: | |
623 self.notify = False | |
624 else: | |
625 raise BadRequest(text="Field notify must be a boolean value") | |
626 | |
627 | |
628 def _render_notify(self, verbElement): | |
629 if self.notify is not None: | |
630 verbElement['notify'] = "true" if self.notify else "false" | |
631 | |
632 | |
612 def parseElement(self, element): | 633 def parseElement(self, element): |
613 """ | 634 """ |
614 Parse the publish-subscribe verb and parameters out of a request. | 635 Parse the publish-subscribe verb and parameters out of a request. |
615 """ | 636 """ |
616 generic.Stanza.parseElement(self, element) | 637 generic.Stanza.parseElement(self, element) |
997 | 1018 |
998 d = request.send(self.xmlstream) | 1019 d = request.send(self.xmlstream) |
999 d.addCallback(cb) | 1020 d.addCallback(cb) |
1000 return d | 1021 return d |
1001 | 1022 |
1002 def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None): | 1023 def retractItems(self, service, nodeIdentifier, itemIdentifiers, notify=None, sender=None): |
1003 """ | 1024 """ |
1004 Retract items from a publish subscribe node. | 1025 Retract items from a publish subscribe node. |
1005 | 1026 |
1006 @param service: The publish subscribe service to delete the node from. | 1027 @param service: The publish subscribe service to delete the node from. |
1007 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} | 1028 @type service: L{JID<twisted.words.protocols.jabber.jid.JID>} |
1008 @param nodeIdentifier: The identifier of the node. | 1029 @param nodeIdentifier: The identifier of the node. |
1009 @type nodeIdentifier: C{unicode} | 1030 @type nodeIdentifier: C{unicode} |
1010 @param itemIdentifiers: Identifiers of the items to be retracted. | 1031 @param itemIdentifiers: Identifiers of the items to be retracted. |
1011 @type itemIdentifiers: C{set} | 1032 @type itemIdentifiers: C{set} |
1033 @param notify: True if notification is required | |
1034 @type notify: C{unicode} | |
1012 """ | 1035 """ |
1013 request = PubSubRequest('retract') | 1036 request = PubSubRequest('retract') |
1014 request.recipient = service | 1037 request.recipient = service |
1015 request.nodeIdentifier = nodeIdentifier | 1038 request.nodeIdentifier = nodeIdentifier |
1016 request.itemIdentifiers = itemIdentifiers | 1039 request.itemIdentifiers = itemIdentifiers |
1040 request.notify = notify | |
1017 request.sender = sender | 1041 request.sender = sender |
1018 return request.send(self.xmlstream) | 1042 return request.send(self.xmlstream) |
1019 | 1043 |
1020 def getOptions(self, service, nodeIdentifier, subscriber, | 1044 def getOptions(self, service, nodeIdentifier, subscriber, |
1021 subscriptionIdentifier=None, sender=None): | 1045 subscriptionIdentifier=None, sender=None): |