<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12060] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12060">12060</a></dd>
<dt>Author</dt> <dd>wsanchez@apple.com</dd>
<dt>Date</dt> <dd>2013-12-12 16:10:43 -0800 (Thu, 12 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Move getLocalTimeZone() into calendar resource, which is its only client.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarserverwebcalresourcepy">CalendarServer/trunk/calendarserver/webcal/resource.py</a></li>
<li><a href="#CalendarServertrunktwextapplicationmasterchildpy">CalendarServer/trunk/twext/application/masterchild.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li>CalendarServer/trunk/calendarserver/webcal/test/</li>
<li><a href="#CalendarServertrunkcalendarserverwebcaltest__init__py">CalendarServer/trunk/calendarserver/webcal/test/__init__.py</a></li>
<li><a href="#CalendarServertrunkcalendarserverwebcaltesttest_resourcepy">CalendarServer/trunk/calendarserver/webcal/test/test_resource.py</a></li>
</ul>

<h3>Removed Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwextpythontesttest_timezonepy">CalendarServer/trunk/twext/python/test/test_timezone.py</a></li>
<li><a href="#CalendarServertrunktwextpythontimezonepy">CalendarServer/trunk/twext/python/timezone.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarserverwebcalresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/webcal/resource.py (12059 => 12060)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -28,6 +28,8 @@
</span><span class="cx"> from urlparse import urlparse
</span><span class="cx"> from cgi import parse_qs
</span><span class="cx"> 
</span><ins>+from twisted.internet.defer import succeed
+
</ins><span class="cx"> from twext.web2 import responsecode
</span><span class="cx"> from twext.web2.http import Response
</span><span class="cx"> from twext.web2.http_headers import MimeType
</span><span class="lines">@@ -37,10 +39,10 @@
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.extensions import DAVFile, ReadOnlyResourceMixIn
</span><ins>+from twistedcaldav.timezones import hasTZ
</ins><span class="cx"> 
</span><del>-from twisted.internet.defer import succeed
</del><ins>+DEFAULT_TIMEZONE = &quot;America/Los_Angeles&quot;
</ins><span class="cx"> 
</span><del>-from twext.python.timezone import getLocalTimezone
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class WebCalendarResource (ReadOnlyResourceMixIn, DAVFile):
</span><span class="lines">@@ -75,7 +77,7 @@
</span><span class="cx">         return &quot;Web Calendar&quot;
</span><span class="cx"> 
</span><span class="cx">     def contentType(self):
</span><del>-        return MimeType.fromString(&quot;text/html; charset=utf-8&quot;);
</del><ins>+        return MimeType.fromString(&quot;text/html; charset=utf-8&quot;)
</ins><span class="cx"> 
</span><span class="cx">     def contentEncoding(self):
</span><span class="cx">         return None
</span><span class="lines">@@ -95,8 +97,11 @@
</span><span class="cx">         else:
</span><span class="cx">             cacheAttr = &quot;_htmlContent&quot;
</span><span class="cx">             templateFileName = &quot;standalone.html&quot;
</span><del>-        templateFileName = os.path.join(config.WebCalendarRoot, templateFileName)
</del><span class="cx"> 
</span><ins>+        templateFileName = os.path.join(
+            config.WebCalendarRoot, templateFileName
+        )
+
</ins><span class="cx">         #
</span><span class="cx">         # See if the file changed, and dump the cached template if so.
</span><span class="cx">         # Don't bother to check if we've checked in the past minute.
</span><span class="lines">@@ -135,14 +140,17 @@
</span><span class="cx"> 
</span><span class="cx">         #
</span><span class="cx">         # Get URL of authenticated principal.
</span><del>-        # Don't need to authenticate here because the ACL will have already required it.
</del><ins>+        # Don't need to authenticate here because the ACL will have already
+        # required it.
</ins><span class="cx">         #
</span><del>-        authenticatedPrincipalURL = str(request.authnUser.childOfType(davxml.HRef))
</del><ins>+        authenticatedPrincipalURL = str(
+            request.authnUser.childOfType(davxml.HRef)
+        )
</ins><span class="cx"> 
</span><span class="cx">         def queryValue(arg):
</span><span class="cx">             query = parse_qs(urlparse(request.uri).query, True)
</span><span class="cx">             return query.get(arg, [&quot;&quot;])[0]
</span><del>-            
</del><ins>+
</ins><span class="cx">         #
</span><span class="cx">         # Parse debug query arg
</span><span class="cx">         #
</span><span class="lines">@@ -180,3 +188,36 @@
</span><span class="cx">                 response.headers.setHeader(header, value)
</span><span class="cx"> 
</span><span class="cx">         return response
</span><ins>+
+
+
+try:
+    from Foundation import NSTimeZone
+
+    def lookupSystemTimezone():
+        return NSTimeZone.localTimeZone().name().encode(&quot;utf-8&quot;)
+
+except ImportError:
+    def lookupSystemTimezone():
+        return &quot;&quot;
+
+
+def getLocalTimezone():
+    &quot;&quot;&quot;
+    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}
+    &quot;&quot;&quot;
+    if config.DefaultTimezone:
+        if hasTZ(config.DefaultTimezone):
+            return config.DefaultTimezone
+
+    systemTimezone = lookupSystemTimezone()
+    if hasTZ(systemTimezone):
+        return systemTimezone
+
+    return DEFAULT_TIMEZONE
</ins></span></pre></div>
<a id="CalendarServertrunkcalendarserverwebcaltest__init__py"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/calendarserver/webcal/test/__init__.py (0 => 12060)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,19 @@
</span><ins>+##
+# Copyright (c) 2009-2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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.
+##
+
+&quot;&quot;&quot;
+Calendar Server Web UI tests.
+&quot;&quot;&quot;
</ins></span></pre></div>
<a id="CalendarServertrunkcalendarserverwebcaltesttest_resourcepy"></a>
<div class="addfile"><h4>Added: CalendarServer/trunk/calendarserver/webcal/test/test_resource.py (0 => 12060)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,70 @@
</span><ins>+##
+# Copyright (c) 2012-2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# 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 &quot;AS IS&quot; 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, &quot;lookupSystemTimezone&quot;,
+            self.stubLookup
+        )
+        self.patch(
+            calendarserver.webcal.resource, &quot;hasTZ&quot;, self.stubHasTZ
+        )
+
+    def test_getLocalTimezone(self):
+
+        # Empty config, system timezone known = use system timezone
+        self.patch(config, &quot;DefaultTimezone&quot;, &quot;&quot;)
+        self._storedLookup = &quot;America/New_York&quot;
+        self._storedHasTZ = [True]
+        self.assertEquals(getLocalTimezone(), &quot;America/New_York&quot;)
+
+        # Empty config, system timezone unknown = use DEFAULT_TIMEZONE
+        self.patch(config, &quot;DefaultTimezone&quot;, &quot;&quot;)
+        self._storedLookup = &quot;Unknown/Unknown&quot;
+        self._storedHasTZ = [False]
+        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)
+
+        # Known config value = use config value
+        self.patch(config, &quot;DefaultTimezone&quot;, &quot;America/New_York&quot;)
+        self._storedHasTZ = [True]
+        self.assertEquals(getLocalTimezone(), &quot;America/New_York&quot;)
+
+        # Unknown config value, system timezone known = use system timezone
+        self.patch(config, &quot;DefaultTimezone&quot;, &quot;Unknown/Unknown&quot;)
+        self._storedLookup = &quot;America/New_York&quot;
+        self._storedHasTZ = [True, False]
+        self.assertEquals(getLocalTimezone(), &quot;America/New_York&quot;)
+
+        # Unknown config value, system timezone unknown = use DEFAULT_TIMEZONE
+        self.patch(config, &quot;DefaultTimezone&quot;, &quot;Unknown/Unknown&quot;)
+        self._storedLookup = &quot;Unknown/Unknown&quot;
+        self._storedHasTZ = [False, False]
+        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)
</ins></span></pre></div>
<a id="CalendarServertrunktwextapplicationmasterchildpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twext/application/masterchild.py (12059 => 12060)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -90,6 +90,8 @@
</span><span class="cx">         except TypeError:
</span><span class="cx">             raise UsageError(&quot;Not a protocol: {0}&quot;.format(protocol))
</span><span class="cx"> 
</span><ins>+        #### FIXME: port should be a strport
+
</ins><span class="cx">         # Validate port number
</span><span class="cx">         try:
</span><span class="cx">             try:
</span></span></pre></div>
<a id="CalendarServertrunktwextpythontesttest_timezonepy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/trunk/twext/python/test/test_timezone.py (12059 => 12060)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,65 +0,0 @@
</span><del>-##
-# Copyright (c) 2012-2013 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
-# 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 &quot;AS IS&quot; 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, &quot;lookupSystemTimezone&quot;, self.stubLookup)
-        self.patch(twistedcaldav.timezones,
-            &quot;hasTZ&quot;, self.stubHasTZ)
-
-    def test_getLocalTimezone(self):
-
-        # Empty config, system timezone known = use system timezone
-        self.patch(config, &quot;DefaultTimezone&quot;, &quot;&quot;)
-        self._storedLookup = &quot;America/New_York&quot;
-        self._storedHasTZ = [True]
-        self.assertEquals(getLocalTimezone(), &quot;America/New_York&quot;)
-
-        # Empty config, system timezone unknown = use DEFAULT_TIMEZONE
-        self.patch(config, &quot;DefaultTimezone&quot;, &quot;&quot;)
-        self._storedLookup = &quot;Unknown/Unknown&quot;
-        self._storedHasTZ = [False]
-        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)
-
-        # Known config value = use config value
-        self.patch(config, &quot;DefaultTimezone&quot;, &quot;America/New_York&quot;)
-        self._storedHasTZ = [True]
-        self.assertEquals(getLocalTimezone(), &quot;America/New_York&quot;)
-
-        # Unknown config value, system timezone known = use system timezone
-        self.patch(config, &quot;DefaultTimezone&quot;, &quot;Unknown/Unknown&quot;)
-        self._storedLookup = &quot;America/New_York&quot;
-        self._storedHasTZ = [True, False]
-        self.assertEquals(getLocalTimezone(), &quot;America/New_York&quot;)
-
-        # Unknown config value, system timezone unknown = use DEFAULT_TIMEZONE
-        self.patch(config, &quot;DefaultTimezone&quot;, &quot;Unknown/Unknown&quot;)
-        self._storedLookup = &quot;Unknown/Unknown&quot;
-        self._storedHasTZ = [False, False]
-        self.assertEquals(getLocalTimezone(), DEFAULT_TIMEZONE)
</del></span></pre></div>
<a id="CalendarServertrunktwextpythontimezonepy"></a>
<div class="delfile"><h4>Deleted: CalendarServer/trunk/twext/python/timezone.py (12059 => 12060)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,51 +0,0 @@
</span><del>-##
-# Copyright (c) 2012-2013 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
-# 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 &quot;AS IS&quot; 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 = &quot;America/Los_Angeles&quot;
-
-try:
-    from Foundation import NSTimeZone
-    def lookupSystemTimezone():
-        return NSTimeZone.localTimeZone().name().encode(&quot;utf-8&quot;)
-
-except:
-    def lookupSystemTimezone():
-        return &quot;&quot;
-
-
-def getLocalTimezone():
-    &quot;&quot;&quot;
-    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}
-    &quot;&quot;&quot;
-    if config.DefaultTimezone:
-        if twistedcaldav.timezones.hasTZ(config.DefaultTimezone):
-            return config.DefaultTimezone
-
-    systemTimezone = lookupSystemTimezone()
-    if twistedcaldav.timezones.hasTZ(systemTimezone):
-        return systemTimezone
-
-    return DEFAULT_TIMEZONE
</del></span></pre>
</div>
</div>

</body>
</html>