<!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>[5447] CalendarServer/trunk/twistedcaldav</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.macosforge.org/projects/calendarserver/changeset/5447">5447</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2010-04-08 13:08:34 -0700 (Thu, 08 Apr 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix directory listing to display a proper MIME Type string that is meaningful.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavextensionspy">CalendarServer/trunk/twistedcaldav/extensions.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavstaticpy">CalendarServer/trunk/twistedcaldav/static.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavtesttest_extensionspy">CalendarServer/trunk/twistedcaldav/test/test_extensions.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavextensionspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/extensions.py (5446 => 5447)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/extensions.py        2010-04-08 01:33:35 UTC (rev 5446)
+++ CalendarServer/trunk/twistedcaldav/extensions.py        2010-04-08 20:08:34 UTC (rev 5447)
</span><span class="lines">@@ -519,7 +519,7 @@
</span><span class="cx">         if self.deadProperties().contains((dav_namespace, &quot;resourcetype&quot;)):
</span><span class="cx">             return succeed(self.deadProperties().get((dav_namespace, &quot;resourcetype&quot;)))
</span><span class="cx">         if self.isCollection():
</span><del>-            return succeed(davxml.ResourceType(davxml.Collection(), davxml.Principal()))
</del><ins>+            return succeed(davxml.ResourceType(davxml.Principal(), davxml.Collection()))
</ins><span class="cx">         else:
</span><span class="cx">             return succeed(davxml.ResourceType(davxml.Principal()))
</span><span class="cx"> 
</span><span class="lines">@@ -640,7 +640,7 @@
</span><span class="cx">         d.addCallback(gotBody)
</span><span class="cx">         return d
</span><span class="cx"> 
</span><del>-    @printTracebacks
</del><ins>+    @inlineCallbacks
</ins><span class="cx">     def renderDirectoryBody(self, request):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Generate a directory listing table in HTML.
</span><span class="lines">@@ -656,7 +656,7 @@
</span><span class="cx">         for name in sorted(self.listChildren()):
</span><span class="cx">             child = self.getChild(name)
</span><span class="cx"> 
</span><del>-            url, name, size, lastModified, contentType = self.getChildDirectoryEntry(child, name)
</del><ins>+            url, name, size, lastModified, contentType = (yield self.getChildDirectoryEntry(child, name, request))
</ins><span class="cx"> 
</span><span class="cx">             # FIXME: gray out resources that are not readable
</span><span class="cx">             output.append(
</span><span class="lines">@@ -761,11 +761,12 @@
</span><span class="cx">             d.addCallback(gotValues)
</span><span class="cx">             return d
</span><span class="cx"> 
</span><del>-        d = self.listProperties(request)
-        d.addCallback(gotProperties)
-        return d
</del><ins>+        qnames = (yield self.listProperties(request))
+        result = (yield gotProperties(qnames))
+        returnValue(result)
</ins><span class="cx"> 
</span><del>-    def getChildDirectoryEntry(self, child, name):
</del><ins>+    @inlineCallbacks
+    def getChildDirectoryEntry(self, child, name, request):
</ins><span class="cx">         def orNone(value, default=&quot;?&quot;, f=None):
</span><span class="cx">             if value is None:
</span><span class="cx">                 return default
</span><span class="lines">@@ -782,22 +783,25 @@
</span><span class="cx">         if isinstance(child, MetaDataMixin):
</span><span class="cx">             size = child.contentLength()
</span><span class="cx">             lastModified = child.lastModified()
</span><del>-            contentType = child.contentType()
</del><ins>+            rtypes = []
+            fullrtype = (yield child.resourceType(request))
+            for rtype in fullrtype.children:
+                rtypes.append(rtype.name)
+            if rtypes:
+                rtypes = &quot;(%s)&quot; % (&quot;, &quot;.join(rtypes),)
+            if child.isCollection():
+                contentType = rtypes
+            else:
+                mimeType = child.contentType()
+                contentType = &quot;%s/%s&quot; % (mimeType.mediaType, mimeType.mediaSubtype)
+                if rtypes:
+                    contentType += &quot; %s&quot; % (rtypes,)
</ins><span class="cx">         else:
</span><span class="cx">             size = None
</span><span class="cx">             lastModified = None
</span><span class="cx">             contentType = None
</span><span class="cx"> 
</span><del>-        if self.fp.isdir():
-            contentType = &quot;(collection)&quot;
-        else:
-            contentType = self._orNone(
-                contentType,
-                default=&quot;-&quot;,
-                f=lambda m: &quot;%s/%s %s&quot; % (m.mediaType, m.mediaSubtype, m.params)
-            )
-
-        return (
</del><ins>+        returnValue((
</ins><span class="cx">             url,
</span><span class="cx">             name,
</span><span class="cx">             orNone(size),
</span><span class="lines">@@ -807,7 +811,7 @@
</span><span class="cx">                 f=lambda t: time.strftime(&quot;%Y-%b-%d %H:%M&quot;, time.localtime(t))
</span><span class="cx">              ),
</span><span class="cx">              contentType,
</span><del>-         )
</del><ins>+         ))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavstaticpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/static.py (5446 => 5447)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/static.py        2010-04-08 01:33:35 UTC (rev 5446)
+++ CalendarServer/trunk/twistedcaldav/static.py        2010-04-08 20:08:34 UTC (rev 5447)
</span><span class="lines">@@ -775,6 +775,15 @@
</span><span class="cx"> 
</span><span class="cx">         return True
</span><span class="cx"> 
</span><ins>+    def _initTypeAndEncoding(self):
+
+        # Handle cases not covered by getTypeAndEncoding()
+        if self.isCollection():
+            self._type = &quot;httpd/unix-directory&quot;
+        else:
+            super(AutoProvisioningFileMixIn, self)._initTypeAndEncoding()
+
+
</ins><span class="cx"> class CalendarHomeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeProvisioningResource, DAVFile):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Resource which provisions calendar home collections as needed.
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavtesttest_extensionspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/test/test_extensions.py (5446 => 5447)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/test/test_extensions.py        2010-04-08 01:33:35 UTC (rev 5446)
+++ CalendarServer/trunk/twistedcaldav/test/test_extensions.py        2010-04-08 20:08:34 UTC (rev 5447)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> # -*- coding: utf-8 -*-
</span><span class="cx"> ##
</span><del>-# Copyright (c) 2009 Apple Inc. All rights reserved.
</del><ins>+# Copyright (c) 2009-2010 Apple Inc. All rights reserved.
</ins><span class="cx"> #
</span><span class="cx"> # Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
</span><span class="cx"> # you may not use this file except in compliance with the License.
</span><span class="lines">@@ -15,19 +15,19 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><del>-from xml.etree.cElementTree import XML# , tostring
</del><ins>+from twext.python.filepath import CachingFilePath as FilePath
+from twext.web2.dav import davxml
+from twext.web2.dav.element.base import WebDAVElement
+from twext.web2.http_headers import MimeType
+from twext.web2.static import MetaDataMixin
</ins><span class="cx"> 
</span><ins>+from twisted.internet.defer import inlineCallbacks, succeed
</ins><span class="cx"> from twisted.trial.unittest import TestCase
</span><del>-
-from twisted.internet.defer import inlineCallbacks
-from twext.python.filepath import CachingFilePath as FilePath
-
</del><span class="cx"> from twisted.web.microdom import parseString
</span><del>-from twext.web2.static import MetaDataMixin
</del><span class="cx"> 
</span><span class="cx"> from twistedcaldav.extensions import DAVFile
</span><span class="cx"> 
</span><del>-from twext.web2.dav.element.base import WebDAVElement
</del><ins>+from xml.etree.cElementTree import XML
</ins><span class="cx"> 
</span><span class="cx"> class UnicodeProperty(WebDAVElement):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="lines">@@ -163,7 +163,9 @@
</span><span class="cx">         unicodeChildName = &quot;test&quot;
</span><span class="cx">         def addUnicodeChild(davFile):
</span><span class="cx">             m = MetaDataMixin()
</span><del>-            m.contentType = lambda: u'text/plain'
</del><ins>+            m.contentType = lambda: MimeType.fromString('text/plain')
+            m.resourceType = lambda r: succeed(davxml.ResourceType())
+            m.isCollection = lambda: False
</ins><span class="cx">             davFile.putChild(unicodeChildName, m)
</span><span class="cx">         yield self.doDirectoryTest([nonASCIIFilename], addUnicodeChild,
</span><span class="cx">                                    [nonASCIIFilename.encode(&quot;utf-8&quot;), unicodeChildName])
</span></span></pre>
</div>
</div>

</body>
</html>