[CalendarServer-changes] [11019] CalendarServer/trunk/calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Tue Apr 9 10:12:46 PDT 2013


Revision: 11019
          http://trac.calendarserver.org//changeset/11019
Author:   sagen at apple.com
Date:     2013-04-09 10:12:46 -0700 (Tue, 09 Apr 2013)
Log Message:
-----------
The config tool now handles non-ascii values

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/config.py
    CalendarServer/trunk/calendarserver/tools/test/test_config.py
    CalendarServer/trunk/calendarserver/tools/test/test_gateway.py

Modified: CalendarServer/trunk/calendarserver/tools/config.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/config.py	2013-04-08 21:57:52 UTC (rev 11018)
+++ CalendarServer/trunk/calendarserver/tools/config.py	2013-04-09 17:12:46 UTC (rev 11019)
@@ -158,6 +158,7 @@
         rawInput = sys.stdin.read()
         try:
             plist = readPlistFromString(rawInput)
+            # Note: values in plist will already be unicode
         except xml.parsers.expat.ExpatError, e:
             respondWithError(str(e))
             return
@@ -234,6 +235,10 @@
         for keyPath in WRITABLE_CONFIG_KEYS:
             value = getKeyPath(config, keyPath)
             if value is not None:
+                # Note: config contains utf-8 encoded strings, but plistlib
+                # wants unicode, so decode here:
+                if isinstance(value, str):
+                    value = value.decode("utf-8")
                 setKeyPath(result, keyPath, value)
         respond(command, result)
 
@@ -247,6 +252,7 @@
         writable = WritableConfig(config, config.WritableConfigFile)
         writable.read()
         valuesToWrite = command.get("Values", {})
+        # Note: values are unicode if they contain non-ascii
         for keyPath, value in flattenDictionary(valuesToWrite):
             if keyPath in WRITABLE_CONFIG_KEYS:
                 writable.set(setKeyPath(ConfigDict(), keyPath, value))

Modified: CalendarServer/trunk/calendarserver/tools/test/test_config.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_config.py	2013-04-08 21:57:52 UTC (rev 11018)
+++ CalendarServer/trunk/calendarserver/tools/test/test_config.py	2013-04-09 17:12:46 UTC (rev 11019)
@@ -119,6 +119,8 @@
         self.assertEquals(results["result"]["EnableSSL"], True)
         self.assertEquals(results["result"]["Notifications"]["Services"]["APNS"]["Enabled"], True)
         self.assertEquals(results["result"]["Notifications"]["Services"]["APNS"]["CalDAV"]["CertificatePath"], "/example/changed.cer")
+        dataRoot = "Data/%s/%s" % (unichr(208), u"\ud83d\udca3")
+        self.assertTrue(results["result"]["DataRoot"].endswith(dataRoot))
 
         # The static plist should still have EnableCalDAV = True
         staticPlist = plistlib.readPlist(self.configFileName)
@@ -204,10 +206,12 @@
             <true/>
             <key>Notifications.Services.APNS.CalDAV.CertificatePath</key>
             <string>/example/changed.cer</string>
+            <key>DataRoot</key>
+            <string>Data/%s/%s</string>
         </dict>
 </dict>
 </plist>
-"""
+""" % (unichr(208), u"\ud83d\udca3")
 
 command_bogusCommand = """<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Modified: CalendarServer/trunk/calendarserver/tools/test/test_gateway.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_gateway.py	2013-04-08 21:57:52 UTC (rev 11018)
+++ CalendarServer/trunk/calendarserver/tools/test/test_gateway.py	2013-04-09 17:12:46 UTC (rev 11019)
@@ -124,7 +124,8 @@
         self.assertEquals(results["result"]["RecordName"], ["createdlocation01"])
         self.assertEquals(results["result"]["State"], "CA")
         self.assertEquals(results["result"]["Street"], "1 Infinite Loop")
-        self.assertEquals(results["result"]["RealName"], "Created Location 01 %s" % unichr(208))
+        self.assertEquals(results["result"]["RealName"],
+            "Created Location 01 %s %s" % (unichr(208), u"\ud83d\udca3" ))
         self.assertEquals(results["result"]["Comment"], "Test Comment")
         self.assertEquals(results["result"]["AutoSchedule"], True)
         self.assertEquals(results["result"]["AutoAcceptGroup"], "E5A6142C-4189-4E9E-90B0-9CD0268B314B")
@@ -151,7 +152,6 @@
 
         record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
         self.assertEquals(record, None)
-
         yield self.runCommand(command_createLocation)
 
         directory.flushCaches()
@@ -162,7 +162,8 @@
         augmentService.refresh()
 
         record = directory.recordWithUID("836B1B66-2E9A-4F46-8B1C-3DD6772C20B2")
-        self.assertEquals(record.fullName.decode("utf-8"), "Created Location 01 %s" % unichr(208))
+        self.assertEquals(record.fullName.decode("utf-8"),
+            "Created Location 01 %s %s" % (unichr(208), u"\ud83d\udca3"))
 
         self.assertNotEquals(record, None)
         self.assertEquals(record.autoSchedule, True)
@@ -334,7 +335,7 @@
         <key>GeneratedUID</key>
         <string>836B1B66-2E9A-4F46-8B1C-3DD6772C20B2</string>
         <key>RealName</key>
-        <string>Created Location 01 %s</string>
+        <string>Created Location 01 %s %s</string>
         <key>RecordName</key>
         <array>
                 <string>createdlocation01</string>
@@ -373,7 +374,7 @@
         </array>
 </dict>
 </plist>
-""" % unichr(208)
+""" % (unichr(208), u"\ud83d\udca3")
 
 
 command_createResource = """<?xml version="1.0" encoding="UTF-8"?>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130409/06cb62f7/attachment-0001.html>


More information about the calendarserver-changes mailing list