Skip to content
Permalink
Browse files

Fix directory listing to display a proper MIME Type string that is me…

…aningful.

git-svn-id: https://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk@5447 e27351fd-9f3e-4f54-a53b-843176b1656c
  • Loading branch information...
cyrusdaboo committed Apr 8, 2010
1 parent e96d05d commit 2a1c086b14f0a87ee2125758ba085dbf075e2985
Showing with 43 additions and 28 deletions.
  1. +23 −19 twistedcaldav/extensions.py
  2. +9 −0 twistedcaldav/static.py
  3. +11 −9 twistedcaldav/test/test_extensions.py
@@ -519,7 +519,7 @@ def resourceType(self, request):
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 @@ def gotBody(body, output=output):
d.addCallback(gotBody)
return d

@printTracebacks
@inlineCallbacks
def renderDirectoryBody(self, request):
"""
Generate a directory listing table in HTML.
@@ -656,7 +656,7 @@ def renderDirectoryBody(self, request):
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 @@ def gotValues(items):
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 @@ def orNone(value, default="?", f=None):
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 @@ def orNone(value, default="?", f=None):
f=lambda t: time.strftime("%Y-%b-%d %H:%M", time.localtime(t))
),
contentType,
)
))



@@ -775,6 +775,15 @@ def provisionFile(self):

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.
@@ -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 twisted.trial.unittest import TestCase

from twisted.internet.defer import inlineCallbacks
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.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 @@ def test_nonASCIIListMixedChildren(self):
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])

0 comments on commit 2a1c086

Please sign in to comment.
You can’t perform that action at this time.