[Zope3-checkins]
SVN: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/
Simple opaque property discovery done.
Martijn Pieters
mj at zopatista.com
Sun Oct 10 15:58:46 EDT 2004
Log message for revision 27938:
Simple opaque property discovery done.
Changed:
U Zope3/branches/isarsprint-dav-work/src/zope/app/dav/interfaces.py
U Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.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/interfaces.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/interfaces.py 2004-10-10 19:38:19 UTC (rev 27937)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/interfaces.py 2004-10-10 19:58:46 UTC (rev 27938)
@@ -210,6 +210,9 @@
Any unknown (no interface registered) DAV properties are stored opaquely
keyed on their namespace URI, so we can return them later when requested.
- Thus this is a mapping of a mapping.
+ Thus this is a mapping of a mapping.
+
+ Property values themselves consist of an attributes structure and the
+ actual opaque value, of the form (((attr1, val1), (attr2, val2)), value)
"""
Modified: Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py
===================================================================
--- Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py 2004-10-10 19:38:19 UTC (rev 27937)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/propfind.py 2004-10-10 19:58:46 UTC (rev 27938)
@@ -117,21 +117,37 @@
count += 1
prop.setAttribute('xmlns:%s' % attr_name, ns)
iface = _props[ns]['iface']
- adapter = iface(self.context, None)
initial = {}
- for name in avail.get(ns):
- value = getattr(adapter, name, None)
- if value is not None:
- initial[name] = value
- setUpWidgets(self, iface, IDAVWidget,
- ignoreStickyValues=True, initial=initial,
- names=avail.get(ns))
+
+ if iface:
+ # The registered namespace case
+ adapter = iface(self.context, None)
+ for name in avail.get(ns):
+ value = getattr(adapter, name, None)
+ if value is not None:
+ initial[name] = value
+ setUpWidgets(self, iface, IDAVWidget,
+ ignoreStickyValues=True, initial=initial,
+ names=avail.get(ns))
+ else:
+ # The opaque properties case
+ oprops = IDAVOpaqueNamespaces(self.context, {})
+ for name in avail.get(ns):
+ value = oprops.get(ns, {}).get(name)
+ if value is not None:
+ initial[name] = value[1]
+
for p in avail.get(ns):
el = response.createElement('%s' % p )
if ns is not None and ns != self.default_ns:
el.setAttribute('xmlns', attr_name)
prop.appendChild(el)
- value = getattr(self, p+'_widget')()
+ if iface:
+ # A registered namespace property
+ value = getattr(self, p+'_widget')()
+ else:
+ value = initial[p]
+
if isinstance(value, (unicode, str)):
# Get the widget value here
value = response.createTextNode(value)
@@ -235,13 +251,19 @@
def _propertyResolver(self, _props):
avail = {}
not_avail = {}
+ oprops = IDAVOpaqueNamespaces(self.context, {})
for ns in _props.keys():
iface = _props[ns]['iface']
for p in _props[ns]['props']:
if iface is None:
- l = not_avail.get(ns, [])
- l.append(p)
- not_avail[ns] = l
+ if oprops.get(ns, {}).get(p):
+ l = avail.get(ns, [])
+ l.append(p)
+ avail[ns] = l
+ else:
+ l = not_avail.get(ns, [])
+ l.append(p)
+ not_avail[ns] = l
continue
adapter = iface(self.context, None)
if adapter is None:
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-10 19:38:19 UTC (rev 27937)
+++ Zope3/branches/isarsprint-dav-work/src/zope/app/dav/tests/test_propfind.py 2004-10-10 19:58:46 UTC (rev 27938)
@@ -346,7 +346,7 @@
root = self.rootFolder
zpt = traverse(root, 'zpt')
oprops = IDAVOpaqueNamespaces(zpt)
- oprops['http://foo/bar'] = {'egg': 'spam'}
+ oprops[u'http://foo/bar'] = {u'egg': ((), u'spam')}
body = '''<?xml version="1.0" ?>
<propfind xmlns="DAV:">
<propname/>
@@ -623,7 +623,48 @@
s1 = normalize_xml(request.response._body)
s2 = normalize_xml(expect)
self.assertEqual(s1, s2)
+
+ def test_propfind_opaque_simple(self):
+ root = self.rootFolder
+ zpt = traverse(root, 'zpt')
+ oprops = IDAVOpaqueNamespaces(zpt)
+ oprops[u'http://foo/bar'] = {u'egg': ((), u'spam')}
+ 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">spam</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