[CalendarServer-changes] [11588] CalendarServer/trunk/calendarserver/tools
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 6 17:04:37 PDT 2013
Revision: 11588
http://trac.calendarserver.org//changeset/11588
Author: sagen at apple.com
Date: 2013-08-06 17:04:36 -0700 (Tue, 06 Aug 2013)
Log Message:
-----------
Handle non-ascii values on the calendarserver_config command line
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/config.py
CalendarServer/trunk/calendarserver/tools/test/test_config.py
Modified: CalendarServer/trunk/calendarserver/tools/config.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/config.py 2013-08-06 20:34:33 UTC (rev 11587)
+++ CalendarServer/trunk/calendarserver/tools/config.py 2013-08-07 00:04:36 UTC (rev 11588)
@@ -137,8 +137,23 @@
writable = WritableConfig(config, writeConfigFileName)
writable.read()
+ processArgs(writable, args)
+
+
+def processArgs(writable, args, restart=True):
+ """
+ Perform the read/write operations requested in the command line args.
+ If there are no args, stdin is read, and plist-formatted commands are
+ processed from there.
+ @param writable: the WritableConfig
+ @param args: a list of utf-8 encoded strings
+ @param restart: whether to restart the calendar server after making a
+ config change.
+ """
if args:
for configKey in args:
+ # args come in as utf-8 encoded strings
+ configKey = configKey.decode("utf-8")
if "=" in configKey:
# This is an assignment
@@ -153,9 +168,9 @@
if c is None:
sys.stderr.write("No such config key: %s\n" % configKey)
break
- sys.stdout.write("%s=%s\n" % (configKey, c))
+ sys.stdout.write("%s=%s\n" % (configKey.encode("utf-8"), c))
- writable.save(restart=True)
+ writable.save(restart=restart)
else:
# Read plist commands from stdin
Modified: CalendarServer/trunk/calendarserver/tools/test/test_config.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_config.py 2013-08-06 20:34:33 UTC (rev 11587)
+++ CalendarServer/trunk/calendarserver/tools/test/test_config.py 2013-08-07 00:04:36 UTC (rev 11588)
@@ -16,7 +16,8 @@
from twistedcaldav.test.util import TestCase
from twistedcaldav.config import ConfigDict
-from calendarserver.tools.config import WritableConfig, setKeyPath, getKeyPath, flattenDictionary
+from calendarserver.tools.config import (WritableConfig, setKeyPath, getKeyPath,
+ flattenDictionary, processArgs)
from calendarserver.tools.test.test_gateway import RunCommandTestCase
from twisted.internet.defer import inlineCallbacks
from twisted.python.filepath import FilePath
@@ -89,7 +90,26 @@
self.assertEquals("xy.zzy", WritableConfig.convertToValue("xy.zzy"))
+ def test_processArgs(self):
+ """
+ Ensure utf-8 encoded command line args are handled properly
+ """
+ content = """<plist version="1.0">
+ <dict>
+ <key>key1</key>
+ <string>before</string>
+ </dict>
+</plist>"""
+ self.fp.setContent(PREAMBLE + content)
+ config = ConfigDict()
+ writable = WritableConfig(config, self.configFile)
+ writable.read()
+ processArgs(writable, ["key1=\xf0\x9f\x92\xa3"], restart=False)
+ writable2 = WritableConfig(config, self.configFile)
+ writable2.read()
+ self.assertEquals(writable2.currentConfigSubset, {'key1': u'\U0001f4a3'})
+
class ConfigTestCase(RunCommandTestCase):
@inlineCallbacks
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130806/6dfc611c/attachment.html>
More information about the calendarserver-changes
mailing list