[CalendarServer-changes] [10153] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Dec 11 11:15:04 PST 2012


Revision: 10153
          http://trac.calendarserver.org//changeset/10153
Author:   sagen at apple.com
Date:     2012-12-11 11:15:03 -0800 (Tue, 11 Dec 2012)
Log Message:
-----------
Move timezone.py from calendarserver.platform.darwin to twext.python

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/webcal/resource.py

Added Paths:
-----------
    CalendarServer/trunk/twext/python/test/test_timezone.py
    CalendarServer/trunk/twext/python/timezone.py

Removed Paths:
-------------
    CalendarServer/trunk/calendarserver/platform/darwin/test_timezone.py
    CalendarServer/trunk/calendarserver/platform/darwin/timezone.py

Deleted: CalendarServer/trunk/calendarserver/platform/darwin/test_timezone.py
===================================================================
--- CalendarServer/trunk/calendarserver/platform/darwin/test_timezone.py	2012-12-11 18:45:28 UTC (rev 10152)
+++ CalendarServer/trunk/calendarserver/platform/darwin/test_timezone.py	2012-12-11 19:15:03 UTC (rev 10153)
@@ -1,66 +0,0 @@
-##
-# Copyright (c) 2012 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 twistedcaldav.test.util import TestCase
-from twistedcaldav.config import config
-import calendarserver.platform.darwin.timezone
-import twistedcaldav.timezones
-from calendarserver.platform.darwin.timezone import getLocalTimezone, DEFAULT_TIMEZONE
-
-class DefaultTimezoneTests(TestCase):
-
-    def stubLookup(self):
-        return self._storedLookup
-
-    def stubHasTZ(self, ignored):
-        return self._storedHasTZ.pop()
-
-    def setUp(self):
-        self.patch(calendarserver.platform.darwin.timezone,
-            "lookupSystemTimezone", self.stubLookup)
-        self.patch(twistedcaldav.timezones,
-            "hasTZ", self.stubHasTZ)
-
-    def test_getLocalTimezone(self):
-
-        # Empty config, system timezone known = use system timezone
-        self.patch(config, "DefaultTimezone", "")
-        self._storedLookup = "America/New_York"
-        self._storedHasTZ = [True]
-        self.assertEquals(getLocalTimezone(), "America/New_York")
-
-        # Empty config, system timezone unknown = use DEFAULT_TIMEZONE
-        self.patch(config, "DefaultTimezone", "")
-        self._storedLookup = "Unknown/Unknown"
-        self._storedHasTZ = [False]
-        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)
-
-        # Known config value = use config value
-        self.patch(config, "DefaultTimezone", "America/New_York")
-        self._storedHasTZ = [True]
-        self.assertEquals(getLocalTimezone(), "America/New_York")
-
-        # Unknown config value, system timezone known = use system timezone
-        self.patch(config, "DefaultTimezone", "Unknown/Unknown")
-        self._storedLookup = "America/New_York"
-        self._storedHasTZ = [True, False]
-        self.assertEquals(getLocalTimezone(), "America/New_York")
-
-        # Unknown config value, system timezone unknown = use DEFAULT_TIMEZONE
-        self.patch(config, "DefaultTimezone", "Unknown/Unknown")
-        self._storedLookup = "Unknown/Unknown"
-        self._storedHasTZ = [False, False]
-        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)

Deleted: CalendarServer/trunk/calendarserver/platform/darwin/timezone.py
===================================================================
--- CalendarServer/trunk/calendarserver/platform/darwin/timezone.py	2012-12-11 18:45:28 UTC (rev 10152)
+++ CalendarServer/trunk/calendarserver/platform/darwin/timezone.py	2012-12-11 19:15:03 UTC (rev 10153)
@@ -1,51 +0,0 @@
-##
-# Copyright (c) 2012 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 twistedcaldav.config import config
-import twistedcaldav.timezones
-
-DEFAULT_TIMEZONE = "America/Los_Angeles"
-
-try:
-    from Foundation import NSTimeZone
-    def lookupSystemTimezone():
-        return NSTimeZone.localTimeZone().name().encode("utf-8")
-
-except:
-    def lookupSystemTimezone():
-        return ""
-
-
-def getLocalTimezone():
-    """
-    Returns the default timezone for the server.  The order of precedence is:
-    config.DefaultTimezone, lookupSystemTimezone( ), DEFAULT_TIMEZONE.
-    Also, if neither of the first two values in that list are in the timezone
-    database, DEFAULT_TIMEZONE is returned.
-
-    @return: The server's local timezone name
-    @rtype: C{str}
-    """
-    if config.DefaultTimezone:
-        if twistedcaldav.timezones.hasTZ(config.DefaultTimezone):
-            return config.DefaultTimezone
-
-    systemTimezone = lookupSystemTimezone()
-    if twistedcaldav.timezones.hasTZ(systemTimezone):
-        return systemTimezone
-
-    return DEFAULT_TIMEZONE

Modified: CalendarServer/trunk/calendarserver/webcal/resource.py
===================================================================
--- CalendarServer/trunk/calendarserver/webcal/resource.py	2012-12-11 18:45:28 UTC (rev 10152)
+++ CalendarServer/trunk/calendarserver/webcal/resource.py	2012-12-11 19:15:03 UTC (rev 10153)
@@ -40,7 +40,7 @@
 
 from twisted.internet.defer import succeed
 
-from calendarserver.platform.darwin.timezone import getLocalTimezone
+from twext.python.timezone import getLocalTimezone
 
 
 class WebCalendarResource (ReadOnlyResourceMixIn, DAVFile):

Copied: CalendarServer/trunk/twext/python/test/test_timezone.py (from rev 10152, CalendarServer/trunk/calendarserver/platform/darwin/test_timezone.py)
===================================================================
--- CalendarServer/trunk/twext/python/test/test_timezone.py	                        (rev 0)
+++ CalendarServer/trunk/twext/python/test/test_timezone.py	2012-12-11 19:15:03 UTC (rev 10153)
@@ -0,0 +1,65 @@
+##
+# Copyright (c) 2012 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 twistedcaldav.test.util import TestCase
+from twistedcaldav.config import config
+import twext.python.timezone
+import twistedcaldav.timezones
+from twext.python.timezone import getLocalTimezone, DEFAULT_TIMEZONE
+
+class DefaultTimezoneTests(TestCase):
+
+    def stubLookup(self):
+        return self._storedLookup
+
+    def stubHasTZ(self, ignored):
+        return self._storedHasTZ.pop()
+
+    def setUp(self):
+        self.patch(twext.python.timezone, "lookupSystemTimezone", self.stubLookup)
+        self.patch(twistedcaldav.timezones,
+            "hasTZ", self.stubHasTZ)
+
+    def test_getLocalTimezone(self):
+
+        # Empty config, system timezone known = use system timezone
+        self.patch(config, "DefaultTimezone", "")
+        self._storedLookup = "America/New_York"
+        self._storedHasTZ = [True]
+        self.assertEquals(getLocalTimezone(), "America/New_York")
+
+        # Empty config, system timezone unknown = use DEFAULT_TIMEZONE
+        self.patch(config, "DefaultTimezone", "")
+        self._storedLookup = "Unknown/Unknown"
+        self._storedHasTZ = [False]
+        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)
+
+        # Known config value = use config value
+        self.patch(config, "DefaultTimezone", "America/New_York")
+        self._storedHasTZ = [True]
+        self.assertEquals(getLocalTimezone(), "America/New_York")
+
+        # Unknown config value, system timezone known = use system timezone
+        self.patch(config, "DefaultTimezone", "Unknown/Unknown")
+        self._storedLookup = "America/New_York"
+        self._storedHasTZ = [True, False]
+        self.assertEquals(getLocalTimezone(), "America/New_York")
+
+        # Unknown config value, system timezone unknown = use DEFAULT_TIMEZONE
+        self.patch(config, "DefaultTimezone", "Unknown/Unknown")
+        self._storedLookup = "Unknown/Unknown"
+        self._storedHasTZ = [False, False]
+        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)

Copied: CalendarServer/trunk/twext/python/timezone.py (from rev 10152, CalendarServer/trunk/calendarserver/platform/darwin/timezone.py)
===================================================================
--- CalendarServer/trunk/twext/python/timezone.py	                        (rev 0)
+++ CalendarServer/trunk/twext/python/timezone.py	2012-12-11 19:15:03 UTC (rev 10153)
@@ -0,0 +1,51 @@
+##
+# Copyright (c) 2012 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 twistedcaldav.config import config
+import twistedcaldav.timezones
+
+DEFAULT_TIMEZONE = "America/Los_Angeles"
+
+try:
+    from Foundation import NSTimeZone
+    def lookupSystemTimezone():
+        return NSTimeZone.localTimeZone().name().encode("utf-8")
+
+except:
+    def lookupSystemTimezone():
+        return ""
+
+
+def getLocalTimezone():
+    """
+    Returns the default timezone for the server.  The order of precedence is:
+    config.DefaultTimezone, lookupSystemTimezone( ), DEFAULT_TIMEZONE.
+    Also, if neither of the first two values in that list are in the timezone
+    database, DEFAULT_TIMEZONE is returned.
+
+    @return: The server's local timezone name
+    @rtype: C{str}
+    """
+    if config.DefaultTimezone:
+        if twistedcaldav.timezones.hasTZ(config.DefaultTimezone):
+            return config.DefaultTimezone
+
+    systemTimezone = lookupSystemTimezone()
+    if twistedcaldav.timezones.hasTZ(systemTimezone):
+        return systemTimezone
+
+    return DEFAULT_TIMEZONE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20121211/8cab40ba/attachment-0001.html>


More information about the calendarserver-changes mailing list