[CalendarServer-changes] [12060] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:19:03 PDT 2014


Revision: 12060
          http://trac.calendarserver.org//changeset/12060
Author:   wsanchez at apple.com
Date:     2013-12-12 16:10:43 -0800 (Thu, 12 Dec 2013)
Log Message:
-----------
Move getLocalTimeZone() into calendar resource, which is its only client.

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

Added Paths:
-----------
    CalendarServer/trunk/calendarserver/webcal/test/
    CalendarServer/trunk/calendarserver/webcal/test/__init__.py
    CalendarServer/trunk/calendarserver/webcal/test/test_resource.py

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

Modified: CalendarServer/trunk/calendarserver/webcal/resource.py
===================================================================
--- CalendarServer/trunk/calendarserver/webcal/resource.py	2013-12-12 23:30:28 UTC (rev 12059)
+++ CalendarServer/trunk/calendarserver/webcal/resource.py	2013-12-13 00:10:43 UTC (rev 12060)
@@ -28,6 +28,8 @@
 from urlparse import urlparse
 from cgi import parse_qs
 
+from twisted.internet.defer import succeed
+
 from twext.web2 import responsecode
 from twext.web2.http import Response
 from twext.web2.http_headers import MimeType
@@ -37,10 +39,10 @@
 
 from twistedcaldav.config import config
 from twistedcaldav.extensions import DAVFile, ReadOnlyResourceMixIn
+from twistedcaldav.timezones import hasTZ
 
-from twisted.internet.defer import succeed
+DEFAULT_TIMEZONE = "America/Los_Angeles"
 
-from twext.python.timezone import getLocalTimezone
 
 
 class WebCalendarResource (ReadOnlyResourceMixIn, DAVFile):
@@ -75,7 +77,7 @@
         return "Web Calendar"
 
     def contentType(self):
-        return MimeType.fromString("text/html; charset=utf-8");
+        return MimeType.fromString("text/html; charset=utf-8")
 
     def contentEncoding(self):
         return None
@@ -95,8 +97,11 @@
         else:
             cacheAttr = "_htmlContent"
             templateFileName = "standalone.html"
-        templateFileName = os.path.join(config.WebCalendarRoot, templateFileName)
 
+        templateFileName = os.path.join(
+            config.WebCalendarRoot, templateFileName
+        )
+
         #
         # See if the file changed, and dump the cached template if so.
         # Don't bother to check if we've checked in the past minute.
@@ -135,14 +140,17 @@
 
         #
         # Get URL of authenticated principal.
-        # Don't need to authenticate here because the ACL will have already required it.
+        # Don't need to authenticate here because the ACL will have already
+        # required it.
         #
-        authenticatedPrincipalURL = str(request.authnUser.childOfType(davxml.HRef))
+        authenticatedPrincipalURL = str(
+            request.authnUser.childOfType(davxml.HRef)
+        )
 
         def queryValue(arg):
             query = parse_qs(urlparse(request.uri).query, True)
             return query.get(arg, [""])[0]
-            
+
         #
         # Parse debug query arg
         #
@@ -180,3 +188,36 @@
                 response.headers.setHeader(header, value)
 
         return response
+
+
+
+try:
+    from Foundation import NSTimeZone
+
+    def lookupSystemTimezone():
+        return NSTimeZone.localTimeZone().name().encode("utf-8")
+
+except ImportError:
+    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 hasTZ(config.DefaultTimezone):
+            return config.DefaultTimezone
+
+    systemTimezone = lookupSystemTimezone()
+    if hasTZ(systemTimezone):
+        return systemTimezone
+
+    return DEFAULT_TIMEZONE

Added: CalendarServer/trunk/calendarserver/webcal/test/__init__.py
===================================================================
--- CalendarServer/trunk/calendarserver/webcal/test/__init__.py	                        (rev 0)
+++ CalendarServer/trunk/calendarserver/webcal/test/__init__.py	2013-12-13 00:10:43 UTC (rev 12060)
@@ -0,0 +1,19 @@
+##
+# Copyright (c) 2009-2013 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.
+##
+
+"""
+Calendar Server Web UI tests.
+"""

Added: CalendarServer/trunk/calendarserver/webcal/test/test_resource.py
===================================================================
--- CalendarServer/trunk/calendarserver/webcal/test/test_resource.py	                        (rev 0)
+++ CalendarServer/trunk/calendarserver/webcal/test/test_resource.py	2013-12-13 00:10:43 UTC (rev 12060)
@@ -0,0 +1,70 @@
+##
+# Copyright (c) 2012-2013 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.webcal.resource
+from calendarserver.webcal.resource 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.webcal.resource, "lookupSystemTimezone",
+            self.stubLookup
+        )
+        self.patch(
+            calendarserver.webcal.resource, "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)

Modified: CalendarServer/trunk/twext/application/masterchild.py
===================================================================
--- CalendarServer/trunk/twext/application/masterchild.py	2013-12-12 23:30:28 UTC (rev 12059)
+++ CalendarServer/trunk/twext/application/masterchild.py	2013-12-13 00:10:43 UTC (rev 12060)
@@ -90,6 +90,8 @@
         except TypeError:
             raise UsageError("Not a protocol: {0}".format(protocol))
 
+        #### FIXME: port should be a strport
+
         # Validate port number
         try:
             try:

Deleted: CalendarServer/trunk/twext/python/test/test_timezone.py
===================================================================
--- CalendarServer/trunk/twext/python/test/test_timezone.py	2013-12-12 23:30:28 UTC (rev 12059)
+++ CalendarServer/trunk/twext/python/test/test_timezone.py	2013-12-13 00:10:43 UTC (rev 12060)
@@ -1,65 +0,0 @@
-##
-# Copyright (c) 2012-2013 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)

Deleted: CalendarServer/trunk/twext/python/timezone.py
===================================================================
--- CalendarServer/trunk/twext/python/timezone.py	2013-12-12 23:30:28 UTC (rev 12059)
+++ CalendarServer/trunk/twext/python/timezone.py	2013-12-13 00:10:43 UTC (rev 12060)
@@ -1,51 +0,0 @@
-##
-# Copyright (c) 2012-2013 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: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/f9fc45c7/attachment.html>


More information about the calendarserver-changes mailing list