[CalendarServer-changes] [5447] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 8 13:08:39 PDT 2010


Revision: 5447
          http://trac.macosforge.org/projects/calendarserver/changeset/5447
Author:   cdaboo at apple.com
Date:     2010-04-08 13:08:34 -0700 (Thu, 08 Apr 2010)
Log Message:
-----------
Fix directory listing to display a proper MIME Type string that is meaningful.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/extensions.py
    CalendarServer/trunk/twistedcaldav/static.py
    CalendarServer/trunk/twistedcaldav/test/test_extensions.py

Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- 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)
@@ -519,7 +519,7 @@
         if self.deadProperties().contains((dav_namespace, "resourcetype")):
             return succeed(self.deadProperties().get((dav_namespace, "resourcetype")))
         if self.isCollection():
-            return succeed(davxml.ResourceType(davxml.Collection(), davxml.Principal()))
+            return succeed(davxml.ResourceType(davxml.Principal(), davxml.Collection()))
         else:
             return succeed(davxml.ResourceType(davxml.Principal()))
 
@@ -640,7 +640,7 @@
         d.addCallback(gotBody)
         return d
 
-    @printTracebacks
+    @inlineCallbacks
     def renderDirectoryBody(self, request):
         """
         Generate a directory listing table in HTML.
@@ -656,7 +656,7 @@
         for name in sorted(self.listChildren()):
             child = self.getChild(name)
 
-            url, name, size, lastModified, contentType = self.getChildDirectoryEntry(child, name)
+            url, name, size, lastModified, contentType = (yield self.getChildDirectoryEntry(child, name, request))
 
             # FIXME: gray out resources that are not readable
             output.append(
@@ -761,11 +761,12 @@
             d.addCallback(gotValues)
             return d
 
-        d = self.listProperties(request)
-        d.addCallback(gotProperties)
-        return d
+        qnames = (yield self.listProperties(request))
+        result = (yield gotProperties(qnames))
+        returnValue(result)
 
-    def getChildDirectoryEntry(self, child, name):
+    @inlineCallbacks
+    def getChildDirectoryEntry(self, child, name, request):
         def orNone(value, default="?", f=None):
             if value is None:
                 return default
@@ -782,22 +783,25 @@
         if isinstance(child, MetaDataMixin):
             size = child.contentLength()
             lastModified = child.lastModified()
-            contentType = child.contentType()
+            rtypes = []
+            fullrtype = (yield child.resourceType(request))
+            for rtype in fullrtype.children:
+                rtypes.append(rtype.name)
+            if rtypes:
+                rtypes = "(%s)" % (", ".join(rtypes),)
+            if child.isCollection():
+                contentType = rtypes
+            else:
+                mimeType = child.contentType()
+                contentType = "%s/%s" % (mimeType.mediaType, mimeType.mediaSubtype)
+                if rtypes:
+                    contentType += " %s" % (rtypes,)
         else:
             size = None
             lastModified = None
             contentType = None
 
-        if self.fp.isdir():
-            contentType = "(collection)"
-        else:
-            contentType = self._orNone(
-                contentType,
-                default="-",
-                f=lambda m: "%s/%s %s" % (m.mediaType, m.mediaSubtype, m.params)
-            )
-
-        return (
+        returnValue((
             url,
             name,
             orNone(size),
@@ -807,7 +811,7 @@
                 f=lambda t: time.strftime("%Y-%b-%d %H:%M", time.localtime(t))
              ),
              contentType,
-         )
+         ))
 
 
 

Modified: CalendarServer/trunk/twistedcaldav/static.py
===================================================================
--- 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)
@@ -775,6 +775,15 @@
 
         return True
 
+    def _initTypeAndEncoding(self):
+
+        # Handle cases not covered by getTypeAndEncoding()
+        if self.isCollection():
+            self._type = "httpd/unix-directory"
+        else:
+            super(AutoProvisioningFileMixIn, self)._initTypeAndEncoding()
+
+
 class CalendarHomeProvisioningFile (AutoProvisioningFileMixIn, DirectoryCalendarHomeProvisioningResource, DAVFile):
     """
     Resource which provisions calendar home collections as needed.

Modified: CalendarServer/trunk/twistedcaldav/test/test_extensions.py
===================================================================
--- 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)
@@ -1,6 +1,6 @@
 # -*- coding: utf-8 -*-
 ##
-# Copyright (c) 2009 Apple Inc. All rights reserved.
+# Copyright (c) 2009-2010 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.
@@ -15,19 +15,19 @@
 # limitations under the License.
 ##
 
-from xml.etree.cElementTree import XML# , tostring
+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
 
+from twisted.internet.defer import inlineCallbacks, succeed
 from twisted.trial.unittest import TestCase
-
-from twisted.internet.defer import inlineCallbacks
-from twext.python.filepath import CachingFilePath as FilePath
-
 from twisted.web.microdom import parseString
-from twext.web2.static import MetaDataMixin
 
 from twistedcaldav.extensions import DAVFile
 
-from twext.web2.dav.element.base import WebDAVElement
+from xml.etree.cElementTree import XML
 
 class UnicodeProperty(WebDAVElement):
     """
@@ -163,7 +163,9 @@
         unicodeChildName = "test"
         def addUnicodeChild(davFile):
             m = MetaDataMixin()
-            m.contentType = lambda: u'text/plain'
+            m.contentType = lambda: MimeType.fromString('text/plain')
+            m.resourceType = lambda r: succeed(davxml.ResourceType())
+            m.isCollection = lambda: False
             davFile.putChild(unicodeChildName, m)
         yield self.doDirectoryTest([nonASCIIFilename], addUnicodeChild,
                                    [nonASCIIFilename.encode("utf-8"), unicodeChildName])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100408/424eaa9c/attachment.html>


More information about the calendarserver-changes mailing list