[Zope3-Users] Patched PROPPATCH

Carlo Cardelli ccardelli at iv-srl.it
Fri Sep 15 06:03:36 EDT 2006


Hi all,

I am experimenting with DAV, with the "canonical" configuration:


-- foo.py --
class Foo(object):
     implements(IFoo)

class DavFoo(object):
     implements(IDavFoo)


-- configure.zcml --
<dav:provideInterface for="http://www.myFoo.it/Foo"
                       interface=".interfaces.IDavFoo"/>
<adapter
     provides=".interfaces.IDavFoo"
     for=".interfaces.IFoo"
     permission="zope.Public"
     factory=".foo.DavFoo"/>


Trying to PROPPATCH multiple attributes in a single request, I saw that 
separate instances of 'DavFoo' were created for each attribute setting.
So I patched zope.app.dav.proppatch.py in the following way:

======================================================================

--- C:\Python24\Lib\site-packages\zope\app\dav\proppatch.py-ori	Fri Sep 
15 10:55:40 2006
+++ C:\Python24\Lib\site-packages\zope\app\dav\proppatch.py	Fri Sep 15 
11:37:10 2006
@@ -33,6 +33,7 @@
      def __init__(self, context, request):
          self.context = context
          self.request = request
+        self.DAVcontext = {}
          ct = request.getHeader('content-type', 'text/xml')
          if ';' in ct:
              parts = ct.split(';', 1)
@@ -99,6 +100,13 @@
              for node in prop[0].childNodes:
                  if not node.nodeType == node.ELEMENT_NODE:
                      continue
+                ns = node.namespaceURI
+                if ns not in self.DAVcontext:
+                    iface = zapi.queryUtility(IDAVNamespace, ns)
+                    if iface:
+                        self.DAVcontext[ns] = iface(self.context)
+                    else:
+                        self.DAVcontext[ns] = None
                  if update.localName == 'set':
                      status = self._handleSet(node)
                  else:
@@ -164,7 +172,7 @@
          if field.readonly:
              return 409 # RFC 2518 specifies 409 for readonly props

-        value = field.get(iface(self.context))
+        value = field.get(self.DAVcontext[ns])
          if value is field.missing_value:
              value = no_value
          setUpWidget(self, prop.localName, field, IDAVWidget,
@@ -176,7 +184,7 @@
          if not widget.hasValidInput():
              return 409 # Didn't match the widget validation

-        if widget.applyChanges(iface(self.context)):
+        if widget.applyChanges(self.DAVcontext[ns]):
              return 200

          return 422 # Field didn't accept the value
@@ -203,9 +211,9 @@
              if field.default is None:
                  return 409 # Clearing a required property is a conflict
              # Reset the field to the default if a value is required
-            field.set(iface(self.context), field.default)
+            field.set(self.DAVcontext[ns], field.default)
              return 200

          # Reset the field to it's defined missing_value
-        field.set(iface(self.context), field.missing_value)
+        field.set(self.DAVcontext[ns], field.missing_value)
          return 200

======================================================================

It seems to be fixed now, i.e. only one instance of DavFoo is created 
for every request.
Could someone validate this, and eventually submit it in the trunk?

Thank you in advance.

Carlo Cardelli.




More information about the Zope3-users mailing list