[CalendarServer-changes] [4776] CalendarServer/branches/release/CalendarServer-2.4-dev
source_changes at macosforge.org
source_changes at macosforge.org
Wed Nov 18 15:17:03 PST 2009
Revision: 4776
http://trac.macosforge.org/projects/calendarserver/changeset/4776
Author: glyph at apple.com
Date: 2009-11-18 15:17:01 -0800 (Wed, 18 Nov 2009)
Log Message:
-----------
Pull up a modified r4722 from trunk; tests are still in test_stdconfig but the implementation fix now lives in config.py.
Revision Links:
--------------
http://trac.macosforge.org/projects/calendarserver/changeset/4722
Modified Paths:
--------------
CalendarServer/branches/release/CalendarServer-2.4-dev/twext/python/plistlib.py
CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/config.py
Added Paths:
-----------
CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_stdconfig.py
Property Changed:
----------------
CalendarServer/branches/release/CalendarServer-2.4-dev/
Property changes on: CalendarServer/branches/release/CalendarServer-2.4-dev
___________________________________________________________________
Modified: svn:mergeinfo
- /CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/trunk:4439-4440,4448,4450,4464,4473-4475,4602,4711-4712,4716-4717,4739-4742,4748-4752,4758,4760,4762
+ /CalendarServer/branches/users/sagen/resource-delegates-4038:4040-4067
/CalendarServer/branches/users/sagen/resource-delegates-4066:4068-4075
/CalendarServer/trunk:4439-4440,4448,4450,4464,4473-4475,4602,4711-4712,4716-4717,4722,4739-4742,4748-4752,4758,4760,4762
Modified: CalendarServer/branches/release/CalendarServer-2.4-dev/twext/python/plistlib.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-2.4-dev/twext/python/plistlib.py 2009-11-18 22:38:05 UTC (rev 4775)
+++ CalendarServer/branches/release/CalendarServer-2.4-dev/twext/python/plistlib.py 2009-11-18 23:17:01 UTC (rev 4776)
@@ -16,15 +16,8 @@
try:
_plistlib = __import__("plistlib")
-
except ImportError:
- from twext.python._plistlib import *
+ from twext.python import _plistlib
- import twext.python._plistlib
- __all__ = twext.python._plistlib.__all__
- del twext
-
-else:
- for symbol in _plistlib.__all__:
- globals()[symbol] = getattr(_plistlib, symbol)
- del _plistlib
+import sys
+sys.modules[__name__] = _plistlib
Modified: CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/config.py 2009-11-18 22:38:05 UTC (rev 4775)
+++ CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/config.py 2009-11-18 23:17:01 UTC (rev 4776)
@@ -29,7 +29,7 @@
from twisted.web2.dav import davxml
from twisted.web2.dav.resource import TwistedACLInheritable
-from twext.python.plistlib import readPlist
+from twext.python.plistlib import PlistParser
from twistedcaldav.log import Logger
from twistedcaldav.log import clearLogLevels, setLogLevelForNamespace, InvalidLogLevelError
@@ -37,6 +37,24 @@
KeychainAccessError, KeychainPasswordNotFound, getPasswordFromKeychain
)
+
+
+class NoUnicodePlistParser(PlistParser):
+ """
+ A variant of L{PlistParser} which avoids exposing the 'unicode' data-type
+ to application code when non-ASCII characters are found, instead
+ consistently exposing UTF-8 encoded 'str' objects.
+ """
+
+ def getData(self):
+ """
+ Get the currently-parsed data as a 'str' object.
+ """
+ data = "".join(self.data).encode("utf-8")
+ self.data = []
+ return data
+
+
log = Logger()
class ConfigDict (dict):
@@ -645,8 +663,9 @@
self._configFile = configFile
if configFile:
+ parser = NoUnicodePlistParser()
try:
- configDict = readPlist(configFile)
+ configDict = parser.parse(open(configFile))
except (IOError, OSError):
log.error("Unable to open config file: %s" % (configFile,))
else:
Copied: CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_stdconfig.py (from rev 4722, CalendarServer/trunk/twistedcaldav/test/test_stdconfig.py)
===================================================================
--- CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_stdconfig.py (rev 0)
+++ CalendarServer/branches/release/CalendarServer-2.4-dev/twistedcaldav/test/test_stdconfig.py 2009-11-18 23:17:01 UTC (rev 4776)
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+##
+# Copyright (c) 2005-2009 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+from cStringIO import StringIO
+
+from twisted.python.filepath import FilePath
+from twisted.trial.unittest import TestCase
+
+from twistedcaldav.config import Config, NoUnicodePlistParser, defaultConfig
+
+nonASCIIValue = "→←"
+nonASCIIPlist = "<plist version='1.0'><string>%s</string></plist>" % (
+ nonASCIIValue,
+)
+
+nonASCIIConfigPList = """
+<plist version="1.0">
+ <dict>
+ <key>DataRoot</key>
+ <string>%s</string>
+ </dict>
+</plist>
+""" % (nonASCIIValue,)
+
+class ConfigParsingTests(TestCase):
+ """
+ Tests to verify the behavior of the configuration parser.
+ """
+
+ def test_noUnicodePListParser(self):
+ """
+ L{NoUnicodePlistParser.parse} retrieves non-ASCII property list values
+ as (UTF-8 encoded) 'str' objects, so that a single type is consistently
+ used regardless of the input data.
+ """
+ parser = NoUnicodePlistParser()
+ self.assertEquals(parser.parse(StringIO(nonASCIIPlist)),
+ nonASCIIValue)
+
+
+ def test_parseNonASCIIConfig(self):
+ """
+ Non-ASCII <string>s found as part of a configuration file will be
+ retrieved as UTF-8 encoded 'str' objects, as parsed by
+ L{NoUnicodePlistParser}.
+ """
+ cfg = Config(defaultConfig)
+ tempfile = FilePath(self.mktemp())
+ tempfile.setContent(nonASCIIConfigPList)
+ cfg.loadConfig(tempfile.path)
+ self.assertEquals(cfg.DataRoot, nonASCIIValue)
+
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091118/dd381e83/attachment-0001.html>
More information about the calendarserver-changes
mailing list