[CalendarServer-changes] [7763] CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/ propertystore

source_changes at macosforge.org source_changes at macosforge.org
Mon Jul 11 15:02:30 PDT 2011


Revision: 7763
          http://trac.macosforge.org/projects/calendarserver/changeset/7763
Author:   glyph at apple.com
Date:     2011-07-11 15:02:29 -0700 (Mon, 11 Jul 2011)
Log Message:
-----------
read & test some actual WebDAV properties, not just xattrs

Modified Paths:
--------------
    CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/appledouble_xattr.py
    CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/test/test_appledouble.py

Modified: CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/appledouble_xattr.py
===================================================================
--- CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/appledouble_xattr.py	2011-07-11 22:02:17 UTC (rev 7762)
+++ CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/appledouble_xattr.py	2011-07-11 22:02:29 UTC (rev 7763)
@@ -18,6 +18,8 @@
 
 import struct
 
+from txdav.base.propertystore.xattr import PropertyStore as XattrPropStore
+
 # A lot of this is copied from python/plat-mac/applesingle.py,
 # with data structure information taken from
 # http://www.opensource.apple.com/source/Libc/Libc-391/darwin/copyfile.c
@@ -159,3 +161,22 @@
                 data = data[advance:]
     return attrs
 
+
+
+class PropertyStore(XattrPropStore):
+    """
+    A property store that will read extended attributes from AppleDouble data in
+    "._"-prefixed files alongside their data.
+    """
+
+    # In this case, this prefix will _always_ be the MacOS prefix.  If you're
+    # using this on some other OS, then you're importing some data from MacOS;
+    # no Linux or BSD 'tar' will create AppleDouble files in the first place.
+
+    deadPropertyXattrPrefix = "WebDAV:"
+
+    @property
+    def attrs(self):
+        return attrsFromFile(self.path.sibling("._"+self.path.basename()).open())
+
+

Modified: CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/test/test_appledouble.py
===================================================================
--- CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/test/test_appledouble.py	2011-07-11 22:02:17 UTC (rev 7762)
+++ CalendarServer/branches/users/glyph/xattrs-from-files/txdav/base/propertystore/test/test_appledouble.py	2011-07-11 22:02:29 UTC (rev 7763)
@@ -23,8 +23,17 @@
 from tarfile import TarFile
 from cStringIO import StringIO
 
-from txdav.base.propertystore.appledouble_xattr import attrsFromFile
+from txdav.base.propertystore.appledouble_xattr import (
+    attrsFromFile, PropertyStore
+)
 
+from txdav.base.propertystore.base import PropertyName
+from twisted.python.filepath import FilePath
+from twext.web2.dav.element.rfc2518 import GETContentType, HRef, Depth
+
+# This tar file contains a single file, 'f', with 2 xattrs; 'alpha' with
+# contents 'beta', and 'gamma' with contents 'delta'.
+
 simpleTarWithXattrs = """
 H4sICDvqGk4AA2YudGFyAO2WvU7DMBSFrYofEYmBhdlPkPraTpwMGRBLkUAg2gGmyrShjUhLVFIo
 G4/CwMLIy/A82GlCS6RSEAo/wp90Fec4sa4tnZzY9SM5aYSyG47qdvscVQEhxOUcI5GBEeEMGMVa
@@ -52,3 +61,61 @@
         self.assertEqual(attrsFromFile(tarfile.extractfile("./._f")),
                          {"alpha": "beta", "gamma": "delta"})
 
+
+# The following tar file was also created with a single file, but it was
+# assigned a few bogus properties first, with a python program something like
+# this:
+
+# ps = PropertyStore("bob", lambda : FilePath("tmp/f"))
+# ps[PropertyName.fromElement(HRef)] = HRef("http://sample.example.com/")
+# ps[PropertyName.fromElement(Depth)] = Depth("1")
+# ps[PropertyName.fromElement(GETContentType)] = GETContentType("text/example")
+# ps.flush()
+
+
+samplePropertyTar = """
+H4sICJ/5Gk4AA2YudGFyAO3W3W4SQRQA4EFjiMTGqNErTUavoAjMz/5hJLHRRLZYwVKsRpNmhZWi
+lVLcVhpj0gvvfAVfQBOiFSvxAUyKAhW1mnijiXe+gb3RXSilkCjlAn/i+ZKd3T0zTGYze/bg9UW0
+XFDXEnrW5524ivqBECIJAkZyHUZE4JQzbMXrqEwwpRKRRJmL5gBCBVFiCOf6spoOszcNLWsuJTk1
+n5n8xTgtk5nSJ5Laz/obj4I3zv8IKuPZVCLA/H6mMJlQByM4bqRu6AHKKeF+IimyFdM2x6jAHUzA
+0ZNB9cxFb0KfCzAuKIrZJzoYbcZT6emAzBXiFx1UaQbTU6n09QB1/OnnBg3evmV9SzP/F8zrPe8X
+BzrzX+ZyR/5zSkWESZ/XVfef5z/accCOtiE0osVxOIov4HVWDO00D4aQLW+ezXvbp61NOTQ2Ntq4
+qv/is3l87xiyfT0eRGjfuH7l1ND5Y7et5k5CzxiNbbA5zeYyQgfb+pO6EZ9OG3raMOYzen3cXbO5
+hNDetnGTWb3+WufuFxYfLVfOOUOewWp5pRCT3/HIeLASqoZL5VAxtntg5u1SpFj88kRVPc5SBD2s
+uJ/Fbs3sKowW+dOa/d5HG/p6ZP9wD/OEPWp1xa1W3K4HR4MxdO3lxoRuNe+shfPBsmdZXaqdjqXs
+iB8/XNr63CXn8EgUDbaW+Mrpcj1+88F31ppyNZRfeF369nxNWsOrc+jEi0OlrnvVqv79+wp0r/+s
+s/4zCvX/t+he/wWhh/pPHIxvrv+UCoJobjD8A/hL9bv2W7rVfytf2vOfiYxB/QcAAAAAAAAAAAAA
+AAAAAACgVz8Aa/aaaQAoAAA=
+""".decode('base64')
+
+
+class PropertyStoreTests(TestCase):
+    """
+    Tests for decoding WebDAV properties.
+    """
+
+    def test_propertiesFromTarball(self):
+        """
+        Extracting a tarball with included AppleDouble WebDAV property
+        information should allow properties to be retrieved using
+        L{PropertyStore}.
+        """
+        tf = TarFile.gzopen('sample.tgz', fileobj=StringIO(samplePropertyTar))
+        tmpdir = self.mktemp()
+
+        # Note that 'tarfile' doesn't know anything about xattrs, so while OS
+        # X's 'tar' will restore these as actual xattrs, the 'tarfile' module
+        # will drop "._" parallel files into the directory structure on all
+        # platforms.
+        tf.extractall(tmpdir)
+
+        props = PropertyStore("bob", lambda : FilePath(tmpdir).child('f'))
+
+        self.assertEqual(props[PropertyName.fromElement(HRef)],
+                         HRef("http://sample.example.com/"))
+        self.assertEqual(props[PropertyName.fromElement(Depth)],
+                         Depth("1"))
+        self.assertEqual(props[PropertyName.fromElement(GETContentType)],
+                         GETContentType("text/example"))
+
+
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110711/050a2e3f/attachment-0001.html>


More information about the calendarserver-changes mailing list