[CalendarServer-changes] [6254] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Sep 7 19:03:33 PDT 2010


Revision: 6254
          http://trac.macosforge.org/projects/calendarserver/changeset/6254
Author:   sagen at apple.com
Date:     2010-09-07 19:03:29 -0700 (Tue, 07 Sep 2010)
Log Message:
-----------
Push notification pubsub node paths now begin with /CalDAV or /CardDAV

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/notify.py
    CalendarServer/trunk/twistedcaldav/test/test_notify.py
    CalendarServer/trunk/txdav/caldav/datastore/test/common.py
    CalendarServer/trunk/txdav/carddav/datastore/test/common.py
    CalendarServer/trunk/txdav/common/datastore/file.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/twistedcaldav/notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/notify.py	2010-09-07 21:12:42 UTC (rev 6253)
+++ CalendarServer/trunk/twistedcaldav/notify.py	2010-09-08 02:03:29 UTC (rev 6254)
@@ -108,14 +108,15 @@
 
 class Notifier(LoggingMixIn):
     """
-    Provides a hook for sending changs notifications to the
+    Provides a hook for sending change notifications to the
     L{NotifierFactory}.
     """
 
-    def __init__(self, notifierFactory, label="default", id=None):
+    def __init__(self, notifierFactory, label="default", id=None, prefix=None):
         self._notifierFactory = notifierFactory
         self._ids = { label : self.normalizeID(id) }
         self._notify = True
+        self._prefix = prefix
 
     def normalizeID(self, id):
         urn = "urn:uuid:"
@@ -135,9 +136,8 @@
         self._notify = False
 
     def notify(self, op="update"):
-        for label, id in self._ids.iteritems():
-            if id is None:
-                id = self.getID(label=label)
+        for label in self._ids.iterkeys():
+            id = self.getID(label=label)
             if id is not None:
                 if self._notify:
                     self.log_debug("Notifications are enabled: %s %s %s" %
@@ -150,10 +150,15 @@
         newNotifier = self.__class__(self._notifierFactory)
         newNotifier._ids = self._ids.copy()
         newNotifier._ids[label] = id
+        newNotifier._prefix = self._prefix
         return newNotifier
 
     def getID(self, label="default"):
-        return self._ids.get(label, None)
+        id = self._ids.get(label, None)
+        if self._prefix is None:
+            return id
+        else:
+            return "%s|%s" % (self._prefix, id)
 
 
 class NotificationClientLineProtocol(LineReceiver, LoggingMixIn):
@@ -258,8 +263,8 @@
     def removeObserver(self, observer):
         self.observers.remove(observer)
 
-    def newNotifier(self, label="default", id=None):
-        return Notifier(self, label=label, id=id)
+    def newNotifier(self, label="default", id=None, prefix=None):
+        return Notifier(self, label=label, id=id, prefix=prefix)
 
 
 
@@ -1233,7 +1238,29 @@
     return results
 
 def getPubSubPath(id, pubSubConfiguration):
-    path = "/DAV/%s/" % (pubSubConfiguration['host'],)
+    """
+    Generate a pubsub node path from an id and the pubsub configuration
+    @param id: a string identifying the resource that was modified.  If
+        the id has a "|" in it, what is to the left of the first "|" is
+        treated as a prefix and will be used for the root of the path.
+    @type id: C{str}
+
+    @param pubSubConfiguration: a dictionary containing various relevant
+        configuration data
+    @type pubSubConfiguration: C{dict}
+
+    """
+
+    path = "/"
+
+    try:
+        prefix, id = id.split("|", 1)
+        path += "%s/" % (prefix,)
+    except ValueError:
+        # id has no prefix
+        pass
+
+    path += "%s/" % (pubSubConfiguration['host'],)
     if id:
         path += "%s/" % (id,)
     return path

Modified: CalendarServer/trunk/twistedcaldav/test/test_notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_notify.py	2010-09-07 21:12:42 UTC (rev 6253)
+++ CalendarServer/trunk/twistedcaldav/test/test_notify.py	2010-09-08 02:03:29 UTC (rev 6254)
@@ -61,7 +61,11 @@
         notifier.enableNotify(None)
         self.assertEquals(notifier._notify, True)
 
+        notifier = Notifier(None, id="test", prefix="CalDAV")
+        self.assertEquals("CalDAV|test", notifier.getID())
 
+
+
 class NotificationClientFactoryTests(TestCase):
 
     def setUp(self):
@@ -390,7 +394,7 @@
         self.assertEquals(publishElement.name, "publish")
         self.assertEquals(publishElement.uri, "http://jabber.org/protocol/pubsub")
         self.assertEquals(publishElement["node"],
-            "/DAV/server.example.com/test/")
+            "/server.example.com/test/")
 
     def test_sendWhileNotConnected(self):
         notifier = XMPPNotifier(self.settings, reactor=Clock(),

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2010-09-07 21:12:42 UTC (rev 6253)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2010-09-08 02:03:29 UTC (rev 6254)
@@ -364,10 +364,10 @@
 
     def test_notifierID(self):
         home = self.homeUnderTest()
-        self.assertEquals(home.notifierID(), "home1")
+        self.assertEquals(home.notifierID(), "CalDAV|home1")
         calendar = home.calendarWithName("calendar_1")
-        self.assertEquals(calendar.notifierID(), "home1")
-        self.assertEquals(calendar.notifierID(label="collection"), "home1/calendar_1")
+        self.assertEquals(calendar.notifierID(), "CalDAV|home1")
+        self.assertEquals(calendar.notifierID(label="collection"), "CalDAV|home1/calendar_1")
 
 
     def test_calendarHomeWithUID_exists(self):
@@ -1218,8 +1218,8 @@
     def __init__(self):
         self.reset()
 
-    def newNotifier(self, label="default", id=None):
-        return Notifier(self, label=label, id=id)
+    def newNotifier(self, label="default", id=None, prefix=None):
+        return Notifier(self, label=label, id=id, prefix=prefix)
 
     def send(self, op, id):
         self.history.append((op, id))

Modified: CalendarServer/trunk/txdav/carddav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/test/common.py	2010-09-07 21:12:42 UTC (rev 6253)
+++ CalendarServer/trunk/txdav/carddav/datastore/test/common.py	2010-09-08 02:03:29 UTC (rev 6254)
@@ -264,10 +264,10 @@
 
     def test_notifierID(self):
         home = self.homeUnderTest()
-        self.assertEquals(home.notifierID(), "home1")
+        self.assertEquals(home.notifierID(), "CardDAV|home1")
         addressbook = home.addressbookWithName("addressbook_1")
-        self.assertEquals(addressbook.notifierID(), "home1")
-        self.assertEquals(addressbook.notifierID(label="collection"), "home1/addressbook_1")
+        self.assertEquals(addressbook.notifierID(), "CardDAV|home1")
+        self.assertEquals(addressbook.notifierID(label="collection"), "CardDAV|home1/addressbook_1")
 
 
     def test_addressbookHomeWithUID_exists(self):
@@ -914,8 +914,8 @@
     def __init__(self):
         self.reset()
 
-    def newNotifier(self, label="default", id=None):
-        return Notifier(self, label=label, id=id)
+    def newNotifier(self, label="default", id=None, prefix=None):
+        return Notifier(self, label=label, id=id, prefix=prefix)
 
     def send(self, op, id):
         self.history.append((op, id))

Modified: CalendarServer/trunk/txdav/common/datastore/file.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/file.py	2010-09-07 21:12:42 UTC (rev 6253)
+++ CalendarServer/trunk/txdav/common/datastore/file.py	2010-09-08 02:03:29 UTC (rev 6254)
@@ -53,6 +53,14 @@
 
 ECALENDARTYPE = 0
 EADDRESSBOOKTYPE = 1
+
+# Labels used to identify the class of resource being modified, so that
+# notification systems can target the correct application
+NotifierPrefixes = {
+    ECALENDARTYPE : "CalDAV",
+    EADDRESSBOOKTYPE : "CardDAV",
+}
+
 TOPPATHS = (
     "calendars",
     "addressbooks"
@@ -233,7 +241,8 @@
             homePath = childPath
 
         if self._notifierFactory:
-            notifier = self._notifierFactory.newNotifier(id=uid)
+            notifier = self._notifierFactory.newNotifier(id=uid,
+                prefix=NotifierPrefixes[storeType])
         else:
             notifier = None
 

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2010-09-07 21:12:42 UTC (rev 6253)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2010-09-08 02:03:29 UTC (rev 6254)
@@ -66,6 +66,13 @@
 ECALENDARTYPE = 0
 EADDRESSBOOKTYPE = 1
 
+# Labels used to identify the class of resource being modified, so that
+# notification systems can target the correct application
+NotifierPrefixes = {
+    ECALENDARTYPE : "CalDAV",
+    EADDRESSBOOKTYPE : "CardDAV",
+}
+
 class CommonDataStore(Service, object):
 
     implements(ICalendarStore)
@@ -211,7 +218,8 @@
         resid = data[0][0]
 
         if self._notifierFactory:
-            notifier = self._notifierFactory.newNotifier(id=uid)
+            notifier = self._notifierFactory.newNotifier(id=uid,
+                prefix=NotifierPrefixes[storeType])
         else:
             notifier = None
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100907/551c1f4e/attachment-0001.html>


More information about the calendarserver-changes mailing list