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

source_changes at macosforge.org source_changes at macosforge.org
Mon Oct 27 10:59:18 PDT 2008


Revision: 3235
          http://trac.macosforge.org/projects/calendarserver/changeset/3235
Author:   cdaboo at apple.com
Date:     2008-10-27 10:59:17 -0700 (Mon, 27 Oct 2008)
Log Message:
-----------
Allow unicode lock tokens.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/memcachelock.py
    CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py

Modified: CalendarServer/trunk/twistedcaldav/memcachelock.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/memcachelock.py	2008-10-27 17:49:18 UTC (rev 3234)
+++ CalendarServer/trunk/twistedcaldav/memcachelock.py	2008-10-27 17:59:17 UTC (rev 3235)
@@ -38,6 +38,9 @@
         """
 
         super(MemcacheLock, self).__init__(namespace)
+        if isinstance(locktoken, unicode):
+            locktoken = locktoken.encode("utf-8")
+        assert isinstance(locktoken, str), "Lock token must be a str."
         self._locktoken = locktoken
         self._timeout = timeout
         self._retry_interval = retry_interval

Modified: CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py	2008-10-27 17:49:18 UTC (rev 3234)
+++ CalendarServer/trunk/twistedcaldav/test/test_memcachelock.py	2008-10-27 17:59:17 UTC (rev 3235)
@@ -168,3 +168,29 @@
             True
         )
 
+    @inlineCallbacks
+    def test_acquire_unicode(self):
+        """
+        L{MemCacheProtocol.get} should return a L{Deferred} which is
+        called back with the value and the flag associated with the given key
+        if the server returns a successful result.
+        """
+        lock = MemCacheTestCase.FakedMemcacheLock(self.proto, "lock", u"locking")
+        yield self._test(
+            lock.acquire(),
+            "add lock:locking 0 0 1\r\n1\r\n",
+            "STORED\r\n",
+            True
+        )
+        self.assertTrue(lock._hasLock)
+
+    def test_acquire_invalid_token(self):
+        """
+        L{MemCacheProtocol.get} should return a L{Deferred} which is
+        called back with the value and the flag associated with the given key
+        if the server returns a successful result.
+        """
+        
+        self.assertRaises(AssertionError, MemCacheTestCase.FakedMemcacheLock, *(self.proto, "lock", 1))
+        self.assertRaises(AssertionError, MemCacheTestCase.FakedMemcacheLock, *(self.proto, "lock", ("abc",)))
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20081027/47882298/attachment-0001.html>


More information about the calendarserver-changes mailing list