[Zope3-checkins]
SVN: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/
New strategy for storing opaque properties: as complete XML
fragments. Now
Martijn Pieters
mj at zopatista.com
Mon Oct 11 06:49:31 EDT 2004
Log message for revision 27958:
New strategy for storing opaque properties: as complete XML fragments. Now
complex DAV properties work out-of-the-box, so we add a etst for that too.
Changed:
U Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py
U Zope3/branches/isarsprint-dav-work/src/zope/app/dav/tests/test_propfind.py
-=-
Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py 2004-10-11 10:46:24 UTC (rev 27957)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/opaquenamespaces.py 2004-10-11 10:49:31 UTC (rev 27958)
@@ -18,6 +18,7 @@
__docformat__ = 'restructuredtext'
from UserDict import DictMixin
+from xml.dom import minidom
from zope.interface import implements
from zope.interface.common.mapping import IMapping
@@ -80,14 +81,16 @@
def __delitem__(self, key):
del self._mapping[key]
self._changed()
-
+
+ #
# Convenience methods; storing and retrieving properties through WebDAV
+ #
def renderProperty(self, ns, nsprefix, prop, propel):
"""Render a property as DOM elements"""
value = self.get(ns, {}).get(prop)
if value is None:
return
- el = propel.ownerDocument.createElement('%s' % prop)
+ value = minidom.parseString(value)
+ el = propel.ownerDocument.importNode(value.documentElement, True)
el.setAttribute('xmlns', nsprefix)
- el.appendChild(el.ownerDocument.createTextNode(value[1]))
propel.appendChild(el)
Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/tests/test_propfind.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/tests/test_propfind.py 2004-10-11 10:46:24 UTC (rev 27957)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/tests/test_propfind.py 2004-10-11 10:49:31 UTC (rev 27958)
@@ -346,7 +346,7 @@
root = self.rootFolder
zpt = traverse(root, 'zpt')
oprops = IDAVOpaqueNamespaces(zpt)
- oprops[u'http://foo/bar'] = {u'egg': ((), u'spam')}
+ oprops[u'http://foo/bar'] = {u'egg': '<egg>spam</egg>'}
body = '''<?xml version="1.0" ?>
<propfind xmlns="DAV:">
<propname/>
@@ -628,7 +628,7 @@
root = self.rootFolder
zpt = traverse(root, 'zpt')
oprops = IDAVOpaqueNamespaces(zpt)
- oprops[u'http://foo/bar'] = {u'egg': ((), u'spam')}
+ oprops[u'http://foo/bar'] = {u'egg': '<egg>spam</egg>'}
body = '''<?xml version="1.0" ?>
<propfind xmlns="DAV:">
<prop xmlns:foo="http://foo/bar">
@@ -665,6 +665,52 @@
s2 = normalize_xml(expect)
self.assertEqual(s1, s2)
+ def test_propfind_opaque_complex(self):
+ root = self.rootFolder
+ zpt = traverse(root, 'zpt')
+ oprops = IDAVOpaqueNamespaces(zpt)
+ oprops[u'http://foo/bar'] = {u'egg':
+ '<egg xmlns:bacon="http://bacon">\n'
+ ' <bacon:pork>crispy</bacon:pork>\n'
+ '</egg>\n'}
+ body = '''<?xml version="1.0" ?>
+ <propfind xmlns="DAV:">
+ <prop xmlns:foo="http://foo/bar">
+ <foo:egg />
+ </prop>
+ </propfind>
+ '''
+
+ request = _createRequest(body=body,
+ headers={'Content-type':'text/xml',
+ 'Depth':'0'})
+
+ resource_url = str(zapi.getView(zpt, 'absolute_url', request))
+ expect = '''<?xml version="1.0" ?>
+ <multistatus xmlns="DAV:">
+ <response>
+ <href>%(resource_url)s</href>
+ <propstat>
+ <prop xmlns:a0="http://foo/bar">
+ <egg xmlns="a0" xmlns:bacon="http://bacon">
+ <bacon:pork>crispy</bacon:pork>
+ </egg>
+ </prop>
+ <status>HTTP/1.1 200 OK</status>
+ </propstat>
+ </response>
+ </multistatus>
+ ''' % {'resource_url':resource_url }
+
+ pfind = propfind.PROPFIND(zpt, request)
+ pfind.PROPFIND()
+ # Check HTTP Response
+ self.assertEqual(request.response.getStatus(), 207)
+ self.assertEqual(pfind.getDepth(), '0')
+ s1 = normalize_xml(request.response._body)
+ s2 = normalize_xml(expect)
+ self.assertEqual(s1, s2)
+
def test_suite():
return TestSuite((
makeSuite(TestPlacefulPROPFIND),
More information about the Zope3-Checkins
mailing list