# HG changeset patch # User Goffi # Date 1439676372 -7200 # Node ID 22f0cb2fa7938cd53cdf3498b6935d26bef034c3 # Parent 1564566e4c1fe48dc3d9d8b03ec3e241aa30825e tmp(pubsub): added retract "notify" attribute management diff -r 1564566e4c1f -r 22f0cb2fa793 wokkel/pubsub.py --- a/wokkel/pubsub.py Sat Aug 15 22:24:40 2015 +0200 +++ b/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)