[Checkins] SVN: z3c.dav/trunk/src/z3c/dav/ Remove dependency of
z3.dav on zope.app.file. Use the z3c.davapp.zopeappfile
Michael Kerrin
michael.kerrin at openapp.ie
Tue May 8 14:09:23 EDT 2007
Log message for revision 75628:
Remove dependency of z3.dav on zope.app.file. Use the z3c.davapp.zopeappfile
module to provide WebDAV support for this content objects.
Changed:
U z3c.dav/trunk/src/z3c/dav/adapters.py
D z3c.dav/trunk/src/z3c/dav/deadproperties.py
U z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py
U z3c.dav/trunk/src/z3c/dav/z3-configure.zcml
-=-
Modified: z3c.dav/trunk/src/z3c/dav/adapters.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/adapters.py 2007-05-08 18:02:46 UTC (rev 75627)
+++ z3c.dav/trunk/src/z3c/dav/adapters.py 2007-05-08 18:09:23 UTC (rev 75628)
@@ -15,12 +15,12 @@
"""
__docformat__ = 'restructuredtext'
+from BTrees.OOBTree import OOBTree
+
+from zope import interface
from zope import component
-from zope import interface
-import zope.publisher.interfaces.http
+import zope.annotation.interfaces
from zope.dublincore.interfaces import IDCTimes, IDCDescriptiveProperties
-from zope.annotation.interfaces import IAnnotatable
-import zope.app.file.interfaces
import z3c.dav.coreproperties
@@ -31,9 +31,21 @@
`{DAV:}creationdate`, `{DAV:}displayname` or title, and the
`{DAV:}getlastmodified` WebDAV properties.
- >>> from zope.app.file.file import File
- >>> file = File('some data for a file', 'text/plain')
- >>> adapter = DAVDublinCore(file, None)
+ >>> from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
+ >>> from zope.dublincore.interfaces import IWriteZopeDublinCore
+ >>> from zope.annotation.attribute import AttributeAnnotations
+ >>> import datetime
+ >>> from zope.datetime import tzinfo
+
+ Create some sample content
+
+ >>> class Resource(object):
+ ... pass
+ >>> resource = Resource()
+
+ With no IZopeDublinCore adapters register all properties return None.
+
+ >>> adapter = DAVDublinCore(resource, None)
>>> adapter.displayname is None
True
>>> adapter.creationdate is None
@@ -45,28 +57,22 @@
>>> adapter.getlastmodified is None
True
- >>> from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
- >>> from zope.dublincore.interfaces import IWriteZopeDublinCore
- >>> from zope.annotation.attribute import AttributeAnnotations
- >>> from zope.annotation.interfaces import IAnnotations
- >>> from zope.annotation.interfaces import IAttributeAnnotatable
- >>> import datetime
- >>> from zope.datetime import tzinfo
+ Now define the IZopeDublinCore adapters, the properties can now have
+ non None values.
- >>> interface.classImplements(File, IAttributeAnnotatable)
+ >>> interface.classImplements(Resource,
+ ... zope.annotation.interfaces.IAttributeAnnotatable)
>>> component.getGlobalSiteManager().registerAdapter(
... AttributeAnnotations)
>>> component.getGlobalSiteManager().registerAdapter(
... ZDCAnnotatableAdapter, provided = IWriteZopeDublinCore)
- >>> file = File('some data for a file', 'text/plain')
- >>> IWriteZopeDublinCore(file).created = now = datetime.datetime(
+ >>> IWriteZopeDublinCore(resource).created = now = datetime.datetime(
... 2006, 5, 24, 0, 0, 58, tzinfo = tzinfo(60))
- >>> IWriteZopeDublinCore(file).title = u'Example Test File'
- >>> IWriteZopeDublinCore(file).modified = now = datetime.datetime(
+ >>> IWriteZopeDublinCore(resource).title = u'Example Test File'
+ >>> IWriteZopeDublinCore(resource).modified = now = datetime.datetime(
... 2006, 5, 24, 0, 0, 58, tzinfo = tzinfo(60))
- >>> adapter = DAVDublinCore(file, None)
>>> adapter.creationdate == now
True
>>> adapter.displayname
@@ -74,11 +80,14 @@
>>> adapter.getlastmodified == now
True
>>> adapter.displayname = u'Changed Test File Title'
- >>> IWriteZopeDublinCore(file).title
+ >>> IWriteZopeDublinCore(resource).title
u'Changed Test File Title'
+ Cleanup
+
>>> component.getGlobalSiteManager().unregisterAdapter(
- ... AttributeAnnotations, provided = IAnnotations)
+ ... AttributeAnnotations,
+ ... provided = zope.annotation.interfaces.IAnnotations)
True
>>> component.getGlobalSiteManager().unregisterAdapter(
... ZDCAnnotatableAdapter, provided = IWriteZopeDublinCore)
@@ -86,8 +95,6 @@
"""
interface.implements(z3c.dav.coreproperties.IDAVCoreSchema)
- component.adapts(IAnnotatable,
- zope.publisher.interfaces.http.IHTTPRequest)
def __init__(self, context, request):
self.context = context
@@ -121,73 +128,127 @@
return dc.modified
-class DAVFileGetSchema(object):
+_opaque_namespace_key = "z3c.dav.deadproperties.DAVOpaqueProperties"
+
+class OpaqueProperties(object):
"""
- >>> from zope.app.file.file import File
+ >>> from zope.annotation.attribute import AttributeAnnotations
>>> from zope.interface.verify import verifyObject
- >>> file = File('some data for the file', 'text/plain')
- >>> adapter = DAVFileGetSchema(file, None)
- >>> verifyObject(z3c.dav.coreproperties.IDAVGetSchema, adapter)
- True
- >>> adapter.getcontentlanguage is None
- True
- >>> adapter.getcontentlength
- 22
- >>> adapter.getcontenttype
- 'text/plain'
-
- >>> from zope.dublincore.annotatableadapter import ZDCAnnotatableAdapter
- >>> from zope.dublincore.interfaces import IWriteZopeDublinCore
- >>> from zope.annotation.attribute import AttributeAnnotations
- >>> from zope.annotation.interfaces import IAnnotations
- >>> from zope.annotation.interfaces import IAttributeAnnotatable
- >>> from zope.datetime import tzinfo
- >>> import datetime
- >>> interface.classImplements(File, IAttributeAnnotatable)
>>> component.getGlobalSiteManager().registerAdapter(
- ... AttributeAnnotations)
- >>> component.getGlobalSiteManager().registerAdapter(
- ... ZDCAnnotatableAdapter, provided = IWriteZopeDublinCore)
+ ... AttributeAnnotations,
+ ... (zope.annotation.interfaces.IAnnotatable,),
+ ... zope.annotation.interfaces.IAnnotations)
- >>> file = File('some data for the file', 'text/plain')
- >>> adapter = DAVFileGetSchema(file, None)
+ Initiial the object contains no dead properties.
- >>> adapter.getcontentlanguage is None
+ >>> class DemoContent(object):
+ ... interface.implements(zope.annotation.interfaces.IAnnotatable)
+ >>> resource = DemoContent()
+ >>> opaqueProperties = OpaqueProperties(resource)
+ >>> verifyObject(z3c.dav.interfaces.IOpaquePropertyStorage,
+ ... opaqueProperties)
True
- >>> adapter.getcontentlength
- 22
- >>> adapter.getcontenttype
- 'text/plain'
- >>> adapter.getetag is None # etag is None for now.
+ >>> annotations = zope.annotation.interfaces.IAnnotations(resource)
+ >>> list(annotations)
+ []
+ >>> list(opaqueProperties.getAllProperties())
+ []
+
+ `hasProperty` returns None since we haven't set any properties yet.
+
+ >>> opaqueProperties.hasProperty('{example:}testprop')
+ False
+ >>> opaqueProperties.getProperty('{example:}testprop') is None
True
+ >>> annotations = zope.annotation.interfaces.IAnnotations(resource)
+ >>> list(annotations)
+ []
- >>> component.getGlobalSiteManager().unregisterAdapter(
- ... AttributeAnnotations, provided = IAnnotations)
+ Set the testprop property
+
+ >>> opaqueProperties.setProperty('{examplens:}testprop',
+ ... '<E:testprop xmlns:E="examplens:">Test Property Value</E:testprop>')
+ >>> annotations = zope.annotation.interfaces.IAnnotations(resource)
+ >>> list(annotations[_opaque_namespace_key])
+ ['{examplens:}testprop']
+ >>> annotations[_opaque_namespace_key]['{examplens:}testprop']
+ '<E:testprop xmlns:E="examplens:">Test Property Value</E:testprop>'
+ >>> opaqueProperties.hasProperty('{examplens:}testprop')
True
+ >>> opaqueProperties.getProperty('{examplens:}testprop')
+ '<E:testprop xmlns:E="examplens:">Test Property Value</E:testprop>'
+ >>> list(opaqueProperties.getAllProperties())
+ ['{examplens:}testprop']
+ >>> opaqueProperties.hasProperty('{examplens:}testbadprop')
+ False
+
+ Now we will remove the property we just set up.
+
+ >>> opaqueProperties.removeProperty('{examplens:}testprop')
+ >>> annotations = zope.annotation.interfaces.IAnnotations(resource)
+ >>> list(annotations[_opaque_namespace_key])
+ []
+
+ Test multiple sets to this value.
+
+ >>> opaqueProperties.setProperty('{examplens:}prop0',
+ ... '<E:prop0 xmlns:E="examplens:">PROP0</E:prop0>')
+ >>> opaqueProperties.setProperty('{examplens:}prop1',
+ ... '<E:prop1 xmlns:E="examplens:">PROP1</E:prop1>')
+ >>> opaqueProperties.setProperty('{examplens:}prop2',
+ ... '<E:prop2 xmlns:E="examplens:">PROP2</E:prop2>')
+ >>> list(opaqueProperties.getAllProperties())
+ ['{examplens:}prop0', '{examplens:}prop1', '{examplens:}prop2']
+
+ >>> opaqueProperties.removeProperty('{examplens:}prop0')
+ >>> opaqueProperties.removeProperty('{examplens:}prop1')
+ >>> list(opaqueProperties.getAllProperties())
+ ['{examplens:}prop2']
+
+ Cleanup this test.
+
>>> component.getGlobalSiteManager().unregisterAdapter(
- ... ZDCAnnotatableAdapter, provided = IWriteZopeDublinCore)
+ ... AttributeAnnotations,
+ ... (zope.annotation.interfaces.IAnnotatable,),
+ ... zope.annotation.interfaces.IAnnotations)
True
"""
- interface.implements(z3c.dav.coreproperties.IDAVGetSchema)
- component.adapts(zope.app.file.interfaces.IFile,
- zope.publisher.interfaces.http.IHTTPRequest)
+ interface.implements(z3c.dav.interfaces.IOpaquePropertyStorage)
- def __init__(self, context, request):
- self.context = context
+ _annotations = None
- @property
- def getcontentlanguage(self):
- return None
+ def __init__(self, context):
+ # __parent__ must be set in order for the security to work
+ self.__parent__ = context
+ annotations = zope.annotation.interfaces.IAnnotations(context)
+ oprops = annotations.get(_opaque_namespace_key)
+ if oprops is None:
+ self._annotations = annotations
+ oprops = OOBTree()
- @property
- def getetag(self):
- return None
+ self._mapping = oprops
- @property
- def getcontentlength(self):
- return self.context.getSize()
+ def _changed(self):
+ if self._annotations is not None:
+ self._annotations[_opaque_namespace_key] = self._mapping
+ self._annotations = None
- @property
- def getcontenttype(self):
- return self.context.contentType
+ def getAllProperties(self):
+ for tag in self._mapping.keys():
+ yield tag
+
+ def hasProperty(self, tag):
+ return tag in self._mapping
+
+ def getProperty(self, tag):
+ """Returns None."""
+ return self._mapping.get(tag, None)
+
+ def setProperty(self, tag, value):
+ self._mapping[tag] = value
+ self._changed()
+
+ def removeProperty(self, tag):
+ del self._mapping[tag]
+ self._changed()
Deleted: z3c.dav/trunk/src/z3c/dav/deadproperties.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/deadproperties.py 2007-05-08 18:02:46 UTC (rev 75627)
+++ z3c.dav/trunk/src/z3c/dav/deadproperties.py 2007-05-08 18:09:23 UTC (rev 75628)
@@ -1,148 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-"""Support for dead properties.
-
-$Id$
-"""
-__docformat__ = 'restructuredtext'
-
-from BTrees.OOBTree import OOBTree
-
-from zope import interface
-from zope import component
-from zope.annotation.interfaces import IAnnotatable, IAnnotations
-
-import z3c.dav.interfaces
-
-_opaque_namespace_key = "z3c.dav.deadproperties.DAVOpaqueProperties"
-
-class OpaqueProperties(object):
- """
- >>> from zope.annotation.attribute import AttributeAnnotations
- >>> from zope.interface.verify import verifyObject
- >>> component.getGlobalSiteManager().registerAdapter(
- ... AttributeAnnotations, (IAnnotatable,), IAnnotations)
-
- Initiial the object contains no dead properties.
-
- >>> class DemoContent(object):
- ... interface.implements(IAnnotatable)
- >>> resource = DemoContent()
- >>> opaqueProperties = OpaqueProperties(resource)
- >>> verifyObject(z3c.dav.interfaces.IOpaquePropertyStorage,
- ... opaqueProperties)
- True
- >>> annotations = IAnnotations(resource)
- >>> list(annotations)
- []
- >>> list(opaqueProperties.getAllProperties())
- []
-
- `hasProperty` returns None since we haven't set any properties yet.
-
- >>> opaqueProperties.hasProperty('{example:}testprop')
- False
- >>> opaqueProperties.getProperty('{example:}testprop') is None
- True
- >>> annotations = IAnnotations(resource)
- >>> list(annotations)
- []
-
- Set the testprop property
-
- >>> opaqueProperties.setProperty('{examplens:}testprop',
- ... '<E:testprop xmlns:E="examplens:">Test Property Value</E:testprop>')
- >>> annotations = IAnnotations(resource)
- >>> list(annotations[_opaque_namespace_key])
- ['{examplens:}testprop']
- >>> annotations[_opaque_namespace_key]['{examplens:}testprop']
- '<E:testprop xmlns:E="examplens:">Test Property Value</E:testprop>'
- >>> opaqueProperties.hasProperty('{examplens:}testprop')
- True
- >>> opaqueProperties.getProperty('{examplens:}testprop')
- '<E:testprop xmlns:E="examplens:">Test Property Value</E:testprop>'
- >>> list(opaqueProperties.getAllProperties())
- ['{examplens:}testprop']
- >>> opaqueProperties.hasProperty('{examplens:}testbadprop')
- False
-
- Now we will remove the property we just set up.
-
- >>> opaqueProperties.removeProperty('{examplens:}testprop')
- >>> annotations = IAnnotations(resource)
- >>> list(annotations[_opaque_namespace_key])
- []
-
- Test multiple sets to this value.
-
- >>> opaqueProperties.setProperty('{examplens:}prop0',
- ... '<E:prop0 xmlns:E="examplens:">PROP0</E:prop0>')
- >>> opaqueProperties.setProperty('{examplens:}prop1',
- ... '<E:prop1 xmlns:E="examplens:">PROP1</E:prop1>')
- >>> opaqueProperties.setProperty('{examplens:}prop2',
- ... '<E:prop2 xmlns:E="examplens:">PROP2</E:prop2>')
- >>> list(opaqueProperties.getAllProperties())
- ['{examplens:}prop0', '{examplens:}prop1', '{examplens:}prop2']
-
- >>> opaqueProperties.removeProperty('{examplens:}prop0')
- >>> opaqueProperties.removeProperty('{examplens:}prop1')
- >>> list(opaqueProperties.getAllProperties())
- ['{examplens:}prop2']
-
- Cleanup this test.
-
- >>> component.getGlobalSiteManager().unregisterAdapter(
- ... AttributeAnnotations, (IAnnotatable,), IAnnotations)
- True
-
- """
- interface.implements(z3c.dav.interfaces.IOpaquePropertyStorage)
- component.adapts(IAnnotatable)
-
- _annotations = None
-
- def __init__(self, context):
- # __parent__ must be set in order for the security to work
- self.__parent__ = context
- annotations = IAnnotations(context)
- oprops = annotations.get(_opaque_namespace_key)
- if oprops is None:
- self._annotations = annotations
- oprops = OOBTree()
-
- self._mapping = oprops
-
- def _changed(self):
- if self._annotations is not None:
- self._annotations[_opaque_namespace_key] = self._mapping
- self._annotations = None
-
- def getAllProperties(self):
- for tag in self._mapping.keys():
- yield tag
-
- def hasProperty(self, tag):
- return tag in self._mapping
-
- def getProperty(self, tag):
- """Returns None."""
- return self._mapping.get(tag, None)
-
- def setProperty(self, tag, value):
- self._mapping[tag] = value
- self._changed()
-
- def removeProperty(self, tag):
- del self._mapping[tag]
- self._changed()
Modified: z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py
===================================================================
--- z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py 2007-05-08 18:02:46 UTC (rev 75627)
+++ z3c.dav/trunk/src/z3c/dav/tests/test_doctests.py 2007-05-08 18:09:23 UTC (rev 75628)
@@ -244,7 +244,6 @@
checker = z3c.etree.testing.xmlOutputChecker,
setUp = lockingSetUp,
tearDown = lockingTearDown),
- doctest.DocTestSuite("z3c.dav.deadproperties"),
doctest.DocTestSuite("z3c.dav.adapters"),
doctest.DocTestSuite("z3c.dav.locking",
checker = z3c.etree.testing.xmlOutputChecker,
Modified: z3c.dav/trunk/src/z3c/dav/z3-configure.zcml
===================================================================
--- z3c.dav/trunk/src/z3c/dav/z3-configure.zcml 2007-05-08 18:02:46 UTC (rev 75627)
+++ z3c.dav/trunk/src/z3c/dav/z3-configure.zcml 2007-05-08 18:09:23 UTC (rev 75628)
@@ -4,20 +4,22 @@
Zope3 webdav support - this should all be in a seperate Zope3 package.
-->
+ <!--
+ The folder package is a dependency of the zcmlfiles package
+ -->
<adapter
+ for="zope.app.folder.interfaces.IFolder
+ zope.publisher.interfaces.http.IHTTPRequest"
factory=".adapters.DAVDublinCore"
/>
<adapter
- factory=".adapters.DAVFileGetSchema"
- />
-
- <adapter
- factory=".deadproperties.OpaqueProperties"
+ for="zope.app.folder.interfaces.IFolder"
+ factory=".adapters.OpaqueProperties"
trusted="1"
/>
- <class class=".deadproperties.OpaqueProperties">
+ <class class=".adapters.OpaqueProperties">
<require
permission="zope.Public"
attributes="getAllProperties hasProperty getProperty"
More information about the Checkins
mailing list