[CalendarServer-changes] [4716] CalendarServer/trunk/twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Fri Nov 6 11:24:54 PST 2009
Revision: 4716
http://trac.macosforge.org/projects/calendarserver/changeset/4716
Author: glyph at apple.com
Date: 2009-11-06 11:24:51 -0800 (Fri, 06 Nov 2009)
Log Message:
-----------
test and fix for unicode type being present in a property
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/extensions.py
CalendarServer/trunk/twistedcaldav/test/test_extensions.py
Modified: CalendarServer/trunk/twistedcaldav/extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/extensions.py 2009-11-06 18:44:29 UTC (rev 4715)
+++ CalendarServer/trunk/twistedcaldav/extensions.py 2009-11-06 19:24:51 UTC (rev 4716)
@@ -970,15 +970,16 @@
value = cgi.escape(value)
output.append(
- """<tr class="%(even)s">"""
- """<td valign="top">%(name)s</td>"""
- """<td><pre>%(value)s</pre></td>"""
- """</tr>"""
- % {
- "even": even.state() and "even" or "odd",
- "name": name,
- "value": value,
- }
+ str("""<tr class="%(even)s">"""
+ """<td valign="top">%(name)s</td>"""
+ """<td><pre>%(value)s</pre></td>"""
+ """</tr>"""
+ % {
+ "even": even.state() and "even" or "odd",
+ "name": name,
+ "value": value,
+ }
+ )
)
output.append("</div>")
Modified: CalendarServer/trunk/twistedcaldav/test/test_extensions.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_extensions.py 2009-11-06 18:44:29 UTC (rev 4715)
+++ CalendarServer/trunk/twistedcaldav/test/test_extensions.py 2009-11-06 19:24:51 UTC (rev 4716)
@@ -1,4 +1,4 @@
-# -*- encoding: utf-8 -*-
+# -*- coding: utf-8 -*-
##
# Copyright (c) 2009 Apple Inc. All rights reserved.
#
@@ -23,9 +23,33 @@
from twisted.python.filepath import FilePath
from twisted.web.microdom import parseString
+from twisted.web2.static import MetaDataMixin
from twistedcaldav.extensions import DAVFile
+from twisted.web2.dav.element.base import WebDAVElement
+
+class UnicodeProperty(WebDAVElement):
+ """
+ An element with a unicode name.
+ """
+
+ name = u'unicode'
+
+ allowed_children = {}
+
+
+class StrProperty(WebDAVElement):
+ """
+ An element with a unicode name.
+ """
+
+ name = 'str'
+
+ allowed_children = {}
+
+
+
class SimpleFakeRequest(object):
"""
Emulate a very small portion of the web2 'Request' API, just enough to
@@ -68,31 +92,38 @@
@return: an object implementing the standard library ElementTree interface.
"""
- return XML(parseString(htmlString, beExtremelyLenient=True).toxml().decode("utf-8"))
+ return XML(parseString(htmlString, beExtremelyLenient=True).toxml())
+nonASCIIFilename = u"アニメ.txt"
+
+
class DirectoryListingTest(TestCase):
"""
Test cases for HTML directory listing.
"""
@inlineCallbacks
- def doDirectoryTest(self, expectedNames):
+ def doDirectoryTest(self, addedNames, modify=lambda x: None, expectedNames=None):
"""
Do a test of a L{DAVFile} pointed at a directory, verifying that files
existing with the given names will be faithfully 'played back' via HTML
rendering.
"""
+ if expectedNames is None:
+ expectedNames = addedNames
fp = FilePath(self.mktemp())
fp.createDirectory()
for sampleName in expectedNames:
fp.child(sampleName).touch()
df = DAVFile(fp)
+ modify(df)
responseXML = browserHTML2ETree(
(yield df.render(SimpleFakeRequest('/'))).stream.read()
)
- names = set([element.text for element in responseXML.findall(".//a")])
+ names = set([element.text.encode("utf-8")
+ for element in responseXML.findall(".//a")])
self.assertEquals(set(expectedNames), names)
@@ -101,7 +132,7 @@
Rendering a L{DAVFile} that is backed by a directory will produce an
HTML document including links to its contents.
"""
- return self.doDirectoryTest(['gamma.txt', 'beta.html', 'alpha.xml'])
+ return self.doDirectoryTest([u'gamma.txt', u'beta.html', u'alpha.xml'])
def test_emptyList(self):
@@ -110,4 +141,44 @@
links.
"""
return self.doDirectoryTest([])
-
+
+
+ def test_nonASCIIList(self):
+ """
+ Listing a directory with a file in it that includes characters that
+ fall outside of the 'Basic Latin' and 'Latin-1 Supplement' unicode
+ blocks should result in those characters being rendered as links in the
+ index.
+ """
+ return self.doDirectoryTest([nonASCIIFilename.encode("utf-8")])
+
+
+ @inlineCallbacks
+ def test_nonASCIIListMixedChildren(self):
+ """
+ Listing a directory that contains unicode metadata and non-ASCII
+ characters in a filename should result in a listing that contains the
+ names of both entities.
+ """
+ unicodeChildName = "test"
+ def addUnicodeChild(davFile):
+ m = MetaDataMixin()
+ m.contentType = lambda: u'text/plain'
+ davFile.putChild(unicodeChildName, m)
+ yield self.doDirectoryTest([nonASCIIFilename], addUnicodeChild,
+ [nonASCIIFilename.encode("utf-8"), unicodeChildName])
+
+
+ @inlineCallbacks
+ def test_nonASCIIListMixedProperties(self):
+ """
+ Listing a directory that contains unicode metadata and non-ASCII
+ characters in a filename should result in a listing that contains the
+ names of both entities.
+ """
+ def addUnicodeChild(davFile):
+ davFile.writeProperty(UnicodeProperty(), None)
+ davFile.writeProperty(StrProperty(), None)
+ yield self.doDirectoryTest([nonASCIIFilename], addUnicodeChild,
+ [nonASCIIFilename.encode("utf-8")])
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091106/5b607e49/attachment-0001.html>
More information about the calendarserver-changes
mailing list