[CalendarServer-changes] [5381] CalendarServer/trunk/txdav/propertystore

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 22 20:18:47 PDT 2010


Revision: 5381
          http://trac.macosforge.org/projects/calendarserver/changeset/5381
Author:   wsanchez at apple.com
Date:     2010-03-22 20:18:47 -0700 (Mon, 22 Mar 2010)
Log Message:
-----------
Add none property store.

Added Paths:
-----------
    CalendarServer/trunk/txdav/propertystore/none.py
    CalendarServer/trunk/txdav/propertystore/test/test_none.py

Added: CalendarServer/trunk/txdav/propertystore/none.py
===================================================================
--- CalendarServer/trunk/txdav/propertystore/none.py	                        (rev 0)
+++ CalendarServer/trunk/txdav/propertystore/none.py	2010-03-23 03:18:47 UTC (rev 5381)
@@ -0,0 +1,89 @@
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Property store with no storage.
+"""
+
+from __future__ import absolute_import
+
+__all__ = [
+    "PropertyStore",
+]
+
+import sys
+import errno
+import urllib
+from zlib import compress, decompress, error as ZlibError
+from cPickle import UnpicklingError, loads as unpickle
+
+from twext.web2.dav.davxml import WebDAVDocument
+
+from txdav.propertystore.base import AbstractPropertyStore, PropertyName
+from txdav.idav import PropertyChangeNotAllowedError
+
+
+class PropertyStore(AbstractPropertyStore):
+    """
+    Property store with no storage.
+    """
+    def __init__(self):
+        self.modified = {}
+
+    def __str__(self):
+        return "<%s>" % (self.__class__.__name__,)
+
+    #
+    # Accessors
+    #
+
+    def __delitem__(self, key):
+        if key in self.modified:
+            del self.modified[key]
+        else:
+            raise KeyError(key)
+
+    def __getitem__(self, key):
+        if key in self.modified:
+            return self.modified[key]
+        else:
+            raise KeyError(key)
+
+    def __contains__(self, key):
+        return key in self.modified
+
+    def __setitem__(self, key, value):
+        self.modified[key] = value
+
+    def __iter__(self):
+        return (k for k in self.modified)
+
+    def __len__(self):
+        return len(self.modified)
+
+    #
+    # I/O
+    #
+
+    def flush(self):
+        if self.modified:
+            raise PropertyChangeNotAllowedError(
+                "None property store cannot flush changes.",
+                keys = self.modified.keys()
+            )
+
+    def abort(self):
+        self.modified.clear()

Copied: CalendarServer/trunk/txdav/propertystore/test/test_none.py (from rev 5378, CalendarServer/trunk/txdav/propertystore/test/test_xattr.py)
===================================================================
--- CalendarServer/trunk/txdav/propertystore/test/test_none.py	                        (rev 0)
+++ CalendarServer/trunk/txdav/propertystore/test/test_none.py	2010-03-23 03:18:47 UTC (rev 5381)
@@ -0,0 +1,86 @@
+##
+# Copyright (c) 2010 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+"""
+Property store tests.
+"""
+
+from zope.interface.verify import verifyObject, BrokenMethodImplementation
+
+from twisted.trial import unittest
+
+from twext.python.filepath import FilePath
+from twext.web2.dav import davxml
+
+from txdav.idav import IPropertyStore, PropertyChangeNotAllowedError
+from txdav.propertystore.base import PropertyName
+from txdav.propertystore.none import PropertyStore
+
+
+class PropertyStoreTest(unittest.TestCase):
+    def setUp(self):
+        self.propertyStore = PropertyStore()
+
+    def test_interface(self):
+        try:
+            verifyObject(IPropertyStore, self.propertyStore)
+        except BrokenMethodImplementation, e:
+            self.fail(e)
+
+    def test_flush(self):
+        store = self.propertyStore
+
+        # Flushing no changes is ok
+        store.flush()
+
+        name = propertyName("test")
+        value = davxml.ResponseDescription("Hello, World!")
+
+        store[name] = value
+
+        # Flushing changes isn't allowed
+        self.assertRaises(PropertyChangeNotAllowedError, store.flush)
+
+        # Changes are still here
+        self.assertEquals(store.get(name, None), value)
+
+        # Flushing no changes is ok
+        del store[name]
+        store.flush()
+
+        self.assertEquals(store.get(name, None), None)
+
+
+    def test_abort(self):
+        store = self.propertyStore
+
+        name = propertyName("test")
+        value = davxml.ResponseDescription("Hello, World!")
+
+        store[name] = value
+
+        store.abort()
+
+        self.assertEquals(store.get(name, None), None)
+        self.assertEquals(store.modified, {})
+
+
+if PropertyStore is None:
+    PropertyStoreTest.skip = importErrorMessage
+
+
+def propertyName(name):
+    return PropertyName("http://calendarserver.org/ns/test/", name)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100322/1ce02a25/attachment.html>


More information about the calendarserver-changes mailing list