elrodo1 / pywebdav

Automatically exported from code.google.com/p/pywebdav
0 stars 0 forks source link

python-webdav: recursive <allprops> only yields a subset of properties #70

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Forwarded from http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=710690

Dear Maintainer,

when all properties for a resource and its children are requested,
pywebdav only returns the value of those properties that are also set
on requested collection itself. It does not return the properties that
are only on one of the children (or grandchildren for that
matter). Also, 404 is returned for any property that is on the
requested collection, but not on the current child.

The reason for this is that the list of property names is created once
in pywebdav.lib.propfind.PROPFIND.create_allprop() and applied to each
resource.

Here's a quick hack to fix it:

=== Begin ===
--- propfind.py.old     2013-06-01 17:03:19.031822359 +0200
+++ /usr/lib/python2.7/dist-packages/pywebdav/lib/propfind.py   2013-06-01 
17:08:50.000000000 +0200
@@ -66,7 +66,7 @@

         df = None
         if self.request_type == RT_ALLPROP:
-            df = self.create_allprop()
+            df = self.create_prop(allprop=True)

         if self.request_type == RT_PROPNAME:
             df = self.create_propname()
@@ -78,7 +78,7 @@
             return df

         # no body means ALLPROP!
-        df = self.create_allprop()
+        df = self.create_prop(allprop=True)
         return df

     def create_propname(self):
@@ -118,17 +118,7 @@

         return doc.toxml(encoding="utf-8")

-    def create_allprop(self):
-        """ return a list of all properties """
-        self.proplist = {}
-        self.namespaces = []
-        for ns, plist in self._dataclass.get_propnames(self._uri).items():
-            self.proplist[ns] = plist
-            self.namespaces.append(ns)
-
-        return self.create_prop()
-
-    def create_prop(self):
+    def create_prop(self, allprop=False):
         """ handle a <prop> request

         This will
@@ -156,16 +146,25 @@
         ms.tagName = 'D:multistatus'

         if self._depth == "0":
+            if allprop:
+                self.proplist = self._dataclass.get_propnames(self._uri)
+                self.namespaces = self.proplist.keys()
             gp, bp = self.get_propvalues(self._uri)
             res = self.mk_prop_response(self._uri, gp, bp, doc)
             ms.appendChild(res)

         elif self._depth == "1":
+            if allprop:
+                self.proplist = self._dataclass.get_propnames(self._uri)
+                self.namespaces = self.proplist.keys()
             gp, bp = self.get_propvalues(self._uri)
             res = self.mk_prop_response(self._uri, gp, bp, doc)
             ms.appendChild(res)

             for newuri in self._dataclass.get_childs(self._uri):
+                if allprop:
+                    self.proplist = self._dataclass.get_propnames(newuri)
+                    self.namespaces = self.proplist.keys()
                 gp, bp = self.get_propvalues(newuri)
                 res = self.mk_prop_response(newuri, gp, bp, doc)
                 ms.appendChild(res)
@@ -173,6 +172,9 @@
             uri_list = [self._uri]
             while uri_list:
                 uri = uri_list.pop()
+                if allprop:
+                    self.proplist = self._dataclass.get_propnames(uri)
+                    self.namespaces = self.proplist.keys()
                 gp, bp = self.get_propvalues(uri)
                 res = self.mk_prop_response(uri, gp, bp, doc)
                 ms.appendChild(res)
=== End ===

Not sure why proplist and namespaces are instance variables rather
than getting passed as a parameter to get_propvalues() and why we
namespaces is a separate variable instead of just using
proplist.keys() in mk_propname_response(), so I haven't changed that.

Original issue reported on code.google.com by mathi...@m9s.biz on 1 Jun 2013 at 5:22