Log message for revision 76723:
  litmus props tests 19: propvalnspace and 20:
  propwformed were failing because Zope did not strip off the
  xmlns: attribute attached to XML property values.  We now strip
  off all attributes that look like xmlns declarations.
  
  
  

Changed:
  U   Zope/trunk/doc/CHANGES.txt
  U   Zope/trunk/lib/python/webdav/davcmds.py
  U   Zope/trunk/lib/python/webdav/tests/test_davcmds.py
  A   Zope/trunk/lib/python/webdav/tests/test_xmltools.py
  U   Zope/trunk/lib/python/webdav/xmltools.py

-=-
Modified: Zope/trunk/doc/CHANGES.txt
===================================================================
--- Zope/trunk/doc/CHANGES.txt  2007-06-16 21:37:23 UTC (rev 76722)
+++ Zope/trunk/doc/CHANGES.txt  2007-06-17 01:02:36 UTC (rev 76723)
@@ -97,6 +97,11 @@
 
     Bugs Fixed
 
+      - DAV: litmus props tests 19: propvalnspace and 20:
+        propwformed were failing because Zope did not strip off the
+        xmlns: attribute attached to XML property values.  We now strip
+        off all attributes that look like xmlns declarations.
+
       - DAV: When a client attempted to unlock a resource with a token
         that the resource hadn't been locked with, in the past we
         returned a 204 response.  This was incorrect.  The "correct"

Modified: Zope/trunk/lib/python/webdav/davcmds.py
===================================================================
--- Zope/trunk/lib/python/webdav/davcmds.py     2007-06-16 21:37:23 UTC (rev 
76722)
+++ Zope/trunk/lib/python/webdav/davcmds.py     2007-06-17 01:02:36 UTC (rev 
76723)
@@ -219,8 +219,7 @@
                     else:
                         # xml property
                         attrs={}
-                        prop.remap({ns:'n'})
-                        prop.del_attr('xmlns:n')
+                        prop.remove_namespace_attrs()
                         for attr in prop.attrs():
                             attrs[attr.qname()]=attr.value()
                         md={'__xml_attrs__':attrs}

Modified: Zope/trunk/lib/python/webdav/tests/test_davcmds.py
===================================================================
--- Zope/trunk/lib/python/webdav/tests/test_davcmds.py  2007-06-16 21:37:23 UTC 
(rev 76722)
+++ Zope/trunk/lib/python/webdav/tests/test_davcmds.py  2007-06-17 01:02:36 UTC 
(rev 76723)
@@ -56,9 +56,45 @@
             result.find('<d:status>HTTP/1.1 400 Bad Request</d:status>'),
             -1)
 
+class TestPropPatch(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from webdav.davcmds import PropPatch
+        return PropPatch
+
+    def _makeOne(self, request):
+        klass = self._getTargetClass()
+        return klass(request)
+
+    def test_parse_xml_property_values_with_namespaces(self):
+        """
+        Before Zope 2.11, litmus props tests 19: propvalnspace and 20:
+        propwformed were failing because Zope did not strip off the
+        xmlns: attribute attached to XML property values.  We now strip
+        off all attributes that look like xmlns declarations.
+        """
+
+        reqbody = """<?xml version="1.0" encoding="utf-8" ?>
+                     <propertyupdate xmlns='DAV:'>
+                     <set>
+                     <prop>
+                     <t:valnspace xmlns:t='http://webdav.org/neon/litmus/'>
+                     <foo xmlns='bar'/>
+                     </t:valnspace>
+                     </prop>
+                     </set>
+                     </propertyupdate>"""
+
+        request = {'BODY':reqbody}
+
+        inst = self._makeOne(request)
+        self.assertEqual(len(inst.values), 1)
+        self.assertEqual(inst.values[0][3]['__xml_attrs__'], {})
+
 def test_suite():
     return unittest.TestSuite((
         unittest.makeSuite(TestUnlock),
+        unittest.makeSuite(TestPropPatch),
         ))
 
 if __name__ == '__main__':

Added: Zope/trunk/lib/python/webdav/tests/test_xmltools.py
===================================================================
--- Zope/trunk/lib/python/webdav/tests/test_xmltools.py                         
(rev 0)
+++ Zope/trunk/lib/python/webdav/tests/test_xmltools.py 2007-06-17 01:02:36 UTC 
(rev 76723)
@@ -0,0 +1,36 @@
+import unittest
+
+class TestNode(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from webdav.xmltools import Node
+        return Node
+
+    def _makeOne(self, wrapped):
+        klass = self._getTargetClass()
+        return klass(wrapped)
+
+    def test_remove_namespace_attrs(self):
+        """ A method added in Zope 2.11 which removes any attributes
+        which appear to be XML namespace declarations """
+        class DummyMinidomNode:
+            def __init__(self):
+                self.attributes = {'xmlns:foo':'foo', 'xmlns':'bar', 'a':'b'}
+            def hasAttributes(self):
+                return True
+            def removeAttribute(self, name):
+                del self.attributes[name]
+
+        wrapped = DummyMinidomNode()
+        node = self._makeOne(wrapped)
+        node.remove_namespace_attrs()
+        self.assertEqual(wrapped.attributes, {'a':'b'})
+
+
+def test_suite():
+    return unittest.TestSuite((
+        unittest.makeSuite(TestNode),
+        ))
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: Zope/trunk/lib/python/webdav/tests/test_xmltools.py
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: Zope/trunk/lib/python/webdav/xmltools.py
===================================================================
--- Zope/trunk/lib/python/webdav/xmltools.py    2007-06-16 21:37:23 UTC (rev 
76722)
+++ Zope/trunk/lib/python/webdav/xmltools.py    2007-06-17 01:02:36 UTC (rev 
76723)
@@ -107,6 +107,19 @@
     def attrs(self):
         return [Node(n) for n in self.node.attributes.values()]
 
+    def remove_namespace_attrs(self):
+        # remove all attributes which start with "xmlns:" or
+        # are equal to "xmlns"
+        if self.node.hasAttributes():
+            toremove = []
+            for name, value in self.node.attributes.items():
+                if name.startswith('xmlns:'):
+                    toremove.append(name)
+                if name == 'xmlns':
+                    toremove.append(name)
+            for name in toremove:
+                self.node.removeAttribute(name)
+
     def del_attr(self, name):
         # NOTE: zope calls this after remapping to remove namespace
         #       zope passes attributes like xmlns:n

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to