 +            legacy = True
  
 +        try:
-+            result = unpickle(data)
-+        except UnpicklingError:
++            doc = davxml.WebDAVDocument.fromString(data)
++            result = doc.root_element
++        except ValueError:
 +            legacy = True
 +
 +            try:
-+                doc = davxml.WebDAVDocument.fromString(data)
-+                result = doc.root_element
-+            except ValueError:
++                result = unpickle(data)
++            except UnpicklingError:
 +                msg = ("Invalid property value stored on server: {%s}%s %s"
 +                       % (qname[0], qname[1], data))
 +                log.err(msg)

     def set(self, property):
-        self.attrs[self._encode(property.qname())] = property.toxml()
+        for n in range(20):
+            try:
+                data = compress(pickle(property))
+            except PicklingError, e:
+                log.err("Unable to pickle property %r: %s" % (property, e))
 
+                # Can't pickle this for some reason; fall back to XML serialization
+                data = compress(property.toxml())
+            try:
+                self.attrs[self._encode(property.qname())] = data
+            except IOError, error:

+        #  1- Started with XML
+        #  2- Started compressing the XML due to limits on xattr size
+        #  3- Switched to pickle which is faster, still compressing
+        #  4- Back to compressed XML for interoperability, size
+        #
+        # We only write the current format, but we also read the old
+        # ones for compatibility.
