[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ Allow clients to set,
remove and query dead properties that have to namespace
Michael Kerrin
michael.kerrin at openapp.ie
Wed May 9 14:41:40 EDT 2007
Log message for revision 75657:
Allow clients to set, remove and query dead properties that have to namespace
associated with them. Now all the litmus properties tests should pass.
Changed:
U z3c.dav/trunk/src/z3c/dav/adapters.py
U z3c.dav/trunk/src/z3c/dav/properties.py
U z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py
-=-
Modified: z3c.dav/trunk/src/z3c/dav/adapters.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/adapters.py 2007-05-09 18:39:14 UTC (rev 75656)
+++ z3c.dav/trunk/src/z3c/dav/adapters.py 2007-05-09 18:41:39 UTC (rev 75657)
@@ -205,6 +205,19 @@
>>> list(opaqueProperties.getAllProperties())
['{examplens:}prop2']
+ The key for the opaque storage is the ElementTree tag. The namespace
+ part of this key can be None.
+
+ >>> opaqueProperties.setProperty('prop2',
+ ... '<E:prop2 xmlns:E="examplens:">PROP2</E:prop2>')
+ >>> opaqueProperties.hasProperty('prop2')
+ True
+ >>> opaqueProperties.getProperty('prop2')
+ '<E:prop2 xmlns:E="examplens:">PROP2</E:prop2>'
+ >>> opaqueProperties.removeProperty('prop2')
+ >>> list(opaqueProperties.getAllProperties())
+ ['{examplens:}prop2']
+
Cleanup this test.
>>> component.getGlobalSiteManager().unregisterAdapter(
Modified: z3c.dav/trunk/src/z3c/dav/properties.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/properties.py 2007-05-09 18:39:14 UTC (rev 75656)
+++ z3c.dav/trunk/src/z3c/dav/properties.py 2007-05-09 18:41:39 UTC (rev 75657)
@@ -95,13 +95,48 @@
class OpaqueInputWidget(z3c.dav.widgets.DAVInputWidget):
+ """
+ >>> class Storage(object):
+ ... interface.implements(IOpaquePropertyStorage)
+ ... def __init__(self):
+ ... self.data = {}
+ ... def setProperty(self, tag, value):
+ ... self.data[tag] = value
+ ... def removeProperty(self, tag):
+ ... del self.data[tag]
+ ... def getProperty(self, tag):
+ ... return self.data[tag]
+ >>> storage = Storage()
+
+ >>> from cStringIO import StringIO
+ >>> from z3c.dav.publisher import WebDAVRequest
+ >>> reqdata = '''<propertyupdate xmlns="DAV:">
+ ... <set>
+ ... <prop>
+ ... <high-unicode xmlns="http://webdav.org/neon/litmus/">𐀀</high-unicode>
+ ... </prop>
+ ... </set>
+ ... </propertyupdate>'''
+ >>> request = WebDAVRequest(StringIO(reqdata),
+ ... {'CONTENT_LENGTH': len(reqdata)})
+ >>> request.processInputs()
+
+ >>> prop = OpaqueProperty('{http://webdav.org/neon/litmus/}high-unicode')
+ >>> widget = getWidget(prop, storage, request, type = IDAVInputWidget)
+
+ >>> print widget.getInputValue() #doctest:+XMLDATA
+ <ns0:high-unicode xmlns:ns0="http://webdav.org/neon/litmus/">\xf0\x90\x80\x80</ns0:high-unicode>
+
+ """
+
def getInputValue(self):
- el = self.getProppatchElement()
+ el = self.request.xmlDataSource.findall(
+ "{DAV:}set/{DAV:}prop/%s" % self.context.tag)
etree = z3c.etree.getEngine()
# XXX - ascii seems a bit wrong here
- return etree.tostring(el[0], 'ascii')
+ return etree.tostring(el[-1], "utf-8")
class IOpaqueField(IField):
@@ -109,18 +144,52 @@
namespace = schema.BytesLine( # should this be schema.URI
title = u"Namespace",
description = u"Namespace to which the value belongs",
+ required = False)
+
+ tag = schema.BytesLine(
+ title = u"ElementTree tag",
+ description = u"This is the key used by the opaque properties storage",
required = True)
class OpaqueField(schema.Field):
+ """
+
+ >>> from zope.interface.verify import verifyObject
+ >>> field = OpaqueField(__name__ = 'test',
+ ... title = u'Test opaque field',
+ ... namespace = 'testns:',
+ ... tag = '{testns:}test')
+
+ >>> IOpaqueField.providedBy(field)
+ True
+ >>> field.namespace
+ 'testns:'
+ >>> field.tag
+ '{testns:}test'
+
+ >>> from zope.interface.verify import verifyObject
+ >>> field = OpaqueField(__name__ = 'test',
+ ... title = u'Test opaque field',
+ ... namespace = None,
+ ... tag = 'test')
+ >>> IOpaqueField.providedBy(field)
+ True
+ >>> field.namespace is None
+ True
+ >>> field.tag
+ 'test'
+
+ """
interface.implements(IOpaqueField)
- namespace = FieldProperty(IOpaqueField['namespace'])
+ namespace = FieldProperty(IOpaqueField["namespace"])
+ tag = FieldProperty(IOpaqueField["tag"])
- def __init__(self, namespace = None, **kw):
+ def __init__(self, tag, namespace = None, **kw):
super(OpaqueField, self).__init__(**kw)
self.namespace = namespace
- self.tag = "{%s}%s" %(self.namespace, self.__name__)
+ self.tag = tag
def get(self, obj):
return obj.getProperty(self.tag)
@@ -131,10 +200,26 @@
class OpaqueProperty(object):
"""
+
>>> from zope.interface.verify import verifyObject
>>> prop = OpaqueProperty('{examplens:}testprop')
>>> verifyObject(IDAVProperty, prop)
True
+ >>> IOpaqueField.providedBy(prop.field)
+ True
+ >>> prop.namespace
+ 'examplens:'
+
+ The namespace part of a opaque property can be None.
+
+ >>> prop = OpaqueProperty('testprop')
+ >>> verifyObject(IDAVProperty, prop)
+ True
+ >>> IOpaqueField.providedBy(prop.field)
+ True
+ >>> prop.namespace is None
+ True
+
"""
interface.implements(IDAVProperty)
@@ -146,9 +231,10 @@
self.field = OpaqueField(
__name__ = name,
namespace = namespace,
+ tag = tag,
title = u"",
description = u"")
- self.custom_widget = OpaqueWidget
+ self.custom_widget = OpaqueWidget
self.custom_input_widget = OpaqueInputWidget
self.restricted = False
Modified: z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py 2007-05-09 18:39:14 UTC (rev 75656)
+++ z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py 2007-05-09 18:41:39 UTC (rev 75657)
@@ -117,11 +117,13 @@
def contentSetup(test):
+ z3c.etree.testing.etreeSetup(test)
test.globs["Demo"] = Demo
test.globs["DemoFolder"] = DemoFolder
def contentTeardown(test):
+ z3c.etree.testing.etreeTearDown(test)
del test.globs["Demo"]
del test.globs["DemoFolder"]
@@ -227,7 +229,9 @@
def test_suite():
return unittest.TestSuite((
doctest.DocTestSuite("z3c.dav.properties",
- setUp = contentSetup, tearDown = contentTeardown),
+ checker = z3c.etree.testing.xmlOutputChecker,
+ setUp = contentSetup,
+ tearDown = contentTeardown),
doctest.DocTestSuite("z3c.dav.utils",
checker = z3c.etree.testing.xmlOutputChecker,
setUp = z3c.etree.testing.etreeSetup,
More information about the Checkins
mailing list