diff --git a/src/tmp/wokkel/pubsub.py b/src/tmp/wokkel/pubsub.py index a6345a9b..19d34372 100755 --- a/src/tmp/wokkel/pubsub.py +++ b/src/tmp/wokkel/pubsub.py @@ -86,6 +86,9 @@ PUBSUB_REQUEST = '/iq[@type="get" or @type="set"]/' + \ '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 @@ class PubSubRequest(generic.Stanza): subscriptionIdentifier = None subscriptions = None affiliations = None + notify = None # Map request iq type and subelement name to request verb _requestVerbMap = { @@ -336,7 +340,7 @@ class PubSubRequest(generic.Stanza): '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 @@ class PubSubRequest(generic.Stanza): 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 @@ class PubSubClient(XMPPHandler): 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 @@ class PubSubClient(XMPPHandler): @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)