[Zope3-dev] Re: Completing WebDAV and zwiki

Philipp von Weitershausen philipp at weitershausen.de
Sat Aug 28 06:50:27 EDT 2004


Derrick 'dman' Hudson wrote:

> I'd like to finish WebDAV and zwiki (at least to the point of doing
> what I want it to :-)).  I would really like to use cadaver's 'edit'
> command to conveniently edit wikipages in $EDITOR :-).  I need some
> help.
> 
> The first problem is that zope.app.dav doesn't use the I*Directory
> interfaces that it ought to.  The attached patch fixes this.

Your patch is not completely correct. You can't check for IReadDirectory 
to be implemented. However, getting an adapter for it is correct.

> However, the patch reveals two more problems :
>     1) A wikipage's "content.txt" object doesn't have enough location
>        information to determine its absolute_url.  This is probably a
>        zwiki bug.
> 
>        How does one define the location of an object?  The code that
>        fails is :
>         resource_url = str(zapi.getView(self.context, 'absolute_url', request))
>        AFAICT this line is correct and what's missing is the
>        configuration in zwiki to define absolute_url.

WikiPage makes up an object to represents its text contents. This object 
does not have any context information associated (i.e. 
ILocation-compatible __name__ and __parent__). When I do this, i can at 
least do an 'ls' in cadaver. I still get a 404 on the file, though.

I have attached another patch that rectifies propfind.py and adds the 
necessary context information to zwiki/wikipage.py. Maybe you can take 
it from here and even write some functional tests. This should be easy 
now using cadaver, tcpwatch and the generator script for functional 
doctests.

>     2) DAV requests for the content of a file are indistinguishable
>        from an ordinary HTTP request.  (From tcpflow's trace of
>        cadaver's request I couldn't identify it as DAV)  HTTP requests
>        don't use the filesystem representation, and thus accessing a
>        wikipage's "content.txt" results in a 404 response.
> 
>        I have no idea how this should be solved.  I believe the DAV
>        protocol includes a request for the source of a resource.  Is
>        this really a bug in cadaver that it didn't specify wanting the
>        source?  Does zope even handle source requests?

Yes, DAV requests are HTTP request and I think that's a good thing. DAV 
has a way of getting to an object's source:

http://webdav.org/specs/rfc2518.htm#PROPERTY_source

As far as I understand this, the client is supposed to do a PROPFIND and 
look for the the <link> element below <source>. This element should 
contian a URI point to a resource containing the resource's source (what 
a tongue-twister :)).

I have no idea if clients actually do support this. I have the feeling 
they don't. Yet *if* they do, WebDAV support for WikiPages could look 
differently:

- PROPFIND contains a link to the source. Whether or not an object 
supports source retrieval through WebDAV could be specified thru ZCML:

   <dav:sourceView
       for="zwiki.interfaces.IWikiPage"
       name="content.txt"
       />

- the source is exposed through a regular (browser) view, e.g. 
/@@content.txt, and doesn't have to be an object created on-the-fly:

   <browser:page
       for="zwiki.interfaces.IWikiPage"
       name="content.txt"
       class=".wikipage.WikiPageContent"
       />

Philipp

-------------- next part --------------
Index: src/zope/app/dav/propfind.py
===================================================================
--- src/zope/app/dav/propfind.py	(revision 27302)
+++ src/zope/app/dav/propfind.py	(working copy)
@@ -18,13 +18,13 @@
 from xml.dom import minidom
 from zope.schema import getFieldNamesInOrder
 from zope.app import zapi
+from zope.app.dav.interfaces import IDAVWidget
+from zope.app.filerepresentation.interfaces import IReadDirectory
 from zope.app.container.interfaces import IReadContainer
-from zope.app.dav.interfaces import IDAVWidget
 from zope.app.form.utility import setUpWidgets
 
-from interfaces import IDAVNamespace
+from zope.app.dav.interfaces import IDAVNamespace
 
-
 class PROPFIND(object):
     """PROPFIND handler for all objects"""
 
@@ -177,8 +177,9 @@
         if depth == 'infinity':
             subdepth = 'infinity'
         if depth != '0':
-            if IReadContainer.providedBy(self.context):
-                for id, obj in self.context.items():
+            directory = IReadDirectory(self.context, None)
+            if directory is not None :
+                for id, obj in directory.items() :
                     pfind = zapi.queryView(obj, 'PROPFIND', self.request, None)
                     if pfind is not None:
                         pfind.setDepth(subdepth)
Index: src/zwiki/wikipage.py
===================================================================
--- src/zwiki/wikipage.py	(revision 27302)
+++ src/zwiki/wikipage.py	(working copy)
@@ -172,7 +172,12 @@
 
     def get(self, key, default=None):
         if key == self.content_file: 
-            return ContentFile(self.context)
+            file = ContentFile(self.context)
+            # We need to make the ContentFile instance a child of
+            # WikiPage so that stuff like IAbsoluteURL views work
+            file.__parent__ = self.context
+            file.__name__ = self.content_file
+            return file
         return self.context.get(key, default)
 
     def __iter__(self):
@@ -209,8 +214,7 @@
         else:
             self.context.__delitem__(name)
 
-
-class ContentFile:
+class ContentFile(Contained):
     r"""Adapter for letting a Wiki Page look like a regular file.
 
     Usage:


More information about the Zope3-dev mailing list