# HG changeset patch # User Goffi # Date 1439676372 -7200 # Node ID 2e43eb9d816762d5a0731b0eae14f23bf9ba27f5 # Parent a13be5c2233486b555203394a1582f57a6cc983b tmp(pubsub): added retract "notify" attribute management diff -r a13be5c22334 -r 2e43eb9d8167 src/tmp/wokkel/pubsub.py --- a/src/tmp/wokkel/pubsub.py Sat Aug 15 22:27:39 2015 +0200 +++ b/src/tmp/wokkel/pubsub.py Sun Aug 16 00:06:12 2015 +0200 @@ -86,6 +86,9 @@ 'pubsub[@xmlns="' + NS_PUBSUB + '" or ' + \ '@xmlns="' + NS_PUBSUB_OWNER + '"]' +BOOL_TRUE = ('1','true') +BOOL_FALSE = ('0','false') + class SubscriptionPending(Exception): """ Raised when the requested subscription is pending acceptance. @@ -295,6 +298,7 @@ subscriptionIdentifier = None subscriptions = None affiliations = None + notify = None # Map request iq type and subelement name to request verb _requestVerbMap = { @@ -336,7 +340,7 @@ 'configureGet': ['nodeOrEmpty'], 'configureSet': ['nodeOrEmpty', 'configure'], 'items': ['node', 'maxItems', 'itemIdentifiers', 'subidOrNone'], - 'retract': ['node', 'itemIdentifiers'], + 'retract': ['node', 'notify', 'itemIdentifiers'], 'purge': ['node'], 'delete': ['node'], 'affiliationsGet': ['nodeOrEmpty'], @@ -609,6 +613,23 @@ self.affiliations[entity] = affiliation + def _parse_notify(self, verbElement): + value = verbElement.getAttribute('notify') + + if value: + if value in BOOL_TRUE: + self.notify = True + elif value in BOOL_FALSE: + self.notify = False + else: + raise BadRequest(text="Field notify must be a boolean value") + + + def _render_notify(self, verbElement): + if self.notify is not None: + verbElement['notify'] = "true" if self.notify else "false" + + def parseElement(self, element): """ Parse the publish-subscribe verb and parameters out of a request. @@ -999,7 +1020,7 @@ d.addCallback(cb) return d - def retractItems(self, service, nodeIdentifier, itemIdentifiers, sender=None): + def retractItems(self, service, nodeIdentifier, itemIdentifiers, notify=None, sender=None): """ Retract items from a publish subscribe node. @@ -1009,11 +1030,14 @@ @type nodeIdentifier: C{unicode} @param itemIdentifiers: Identifiers of the items to be retracted. @type itemIdentifiers: C{set} + @param notify: True if notification is required + @type notify: C{unicode} """ request = PubSubRequest('retract') request.recipient = service request.nodeIdentifier = nodeIdentifier request.itemIdentifiers = itemIdentifiers + request.notify = notify request.sender = sender return request.send(self.xmlstream)