diff 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
line wrap: on
line diff
--- 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)