[CalendarServer-changes] [2977] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Sep 11 08:35:45 PDT 2008


Revision: 2977
          http://trac.macosforge.org/projects/calendarserver/changeset/2977
Author:   sagen at apple.com
Date:     2008-09-11 08:35:44 -0700 (Thu, 11 Sep 2008)
Log Message:
-----------
Allow simple line notification client to send a zero to playback entire history, plus send back an empty line if playback would otherwise be empty

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/notify.py
    CalendarServer/trunk/twistedcaldav/test/test_notify.py

Modified: CalendarServer/trunk/twistedcaldav/notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/notify.py	2008-09-11 03:33:43 UTC (rev 2976)
+++ CalendarServer/trunk/twistedcaldav/notify.py	2008-09-11 15:35:44 UTC (rev 2977)
@@ -459,14 +459,18 @@
 
         hist = self.history
         toSend = [(hist[uri], uri) for uri in hist if hist[uri] > oldSeq]
-        toSend.sort() # sorts the tuples based on numeric sequence number
 
-        for seq, uri in toSend:
-            msg = "%d %s" % (seq, uri)
-            self.log_debug("Sending %s" % (msg,))
-            observer.sendLine(msg)
+        if toSend:
+            toSend.sort() # sorts the tuples based on numeric sequence number
+            for seq, uri in toSend:
+                msg = "%d %s" % (seq, uri)
+                self.log_debug("Sending %s" % (msg,))
+                observer.sendLine(msg)
+        else:
+            observer.sendLine("")
 
 
+
     def addObserver(self, observer):
         self.observers.add(observer)
 
@@ -509,10 +513,7 @@
                 self.transport.getPeer()))
             return
 
-        if oldSeq == 0:
-            self.notifier.reset()
-        else:
-            self.notifier.playback(self, oldSeq)
+        self.notifier.playback(self, oldSeq)
 
     def connectionLost(self, reason):
         self.notifier.removeObserver(self)

Modified: CalendarServer/trunk/twistedcaldav/test/test_notify.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_notify.py	2008-09-11 03:33:43 UTC (rev 2976)
+++ CalendarServer/trunk/twistedcaldav/test/test_notify.py	2008-09-11 15:35:44 UTC (rev 2977)
@@ -251,8 +251,14 @@
         self.notifier.enqueue("update", "C")
         protocol = StubProtocol()
         self.notifier.addObserver(protocol)
+        self.notifier.playback(protocol, 0)
+        self.assertEquals(protocol.lines, ["1 A", "2 B", "3 C"])
+        protocol.reset()
         self.notifier.playback(protocol, 1)
         self.assertEquals(protocol.lines, ["2 B", "3 C"])
+        protocol.reset()
+        self.notifier.playback(protocol, 5)
+        self.assertEquals(protocol.lines, [""])
 
     def test_reset(self):
         self.notifier.enqueue("update", "A")
@@ -299,11 +305,13 @@
 class StubProtocol(object):
 
     def __init__(self):
-        self.lines = []
+        self.reset()
 
     def sendLine(self, line):
         self.lines.append(line)
 
+    def reset(self):
+        self.lines = []
 
 class StubTransport(object):
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080911/88543c21/attachment.html 


More information about the calendarserver-changes mailing list