Author: jmorliaguet
Date: Tue Dec 13 15:27:06 2005
New Revision: 2026

Modified:
   cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py
   cpsskins/branches/jmo-perspectives/engines/default/formats/style.py
Log:

- we use btrees instead of persistent mapping



Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py        
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/layout.py        
Tue Dec 13 15:27:06 2005
@@ -17,7 +17,8 @@
 """
 __docformat__ = "reStructuredText"
 
-from persistent.mapping import PersistentMapping
+from BTrees.OOBTree import OOBTree
+from persistent import Persistent
 
 from zope.app.traversing.interfaces import ITraversable
 from zope.component.interfaces import IFactory
@@ -38,7 +39,7 @@
 
 ILayout.setTaggedValue('name', u'layout')
 
-class Layout(Format, PersistentMapping):
+class Layout(Format, Persistent):
     """A layout is used to format layout elements (cells, blocks, etc)
 
     >>> layout = Layout(type=u'container')
@@ -55,11 +56,9 @@
     """
     implements(ILayout, ITraversable)
 
-    __super_setitem = PersistentMapping.__setitem__
-
     def __init__(self, **kw):
         super(Layout, self).__init__(**kw)
-        self.data = PersistentMapping()
+        self.data = OOBTree()
 
     def __repr__(self):
         return "<Layout of type: %s>" % self.type
@@ -73,9 +72,20 @@
         if not isinstance(v, basestring):
             raise TypeError, \
                 """Only strings can be stored in the layout objects."""
-        if k in self:
-            del self[k]
-        self.__super_setitem(k, v)
+        if k in self.data:
+            del self.data[k]
+        self.data[k] = v
+
+    def __getitem__(self, k):
+        return self.data[k]
+
+    def __contains__(self, k):
+        return k in self.data
+
+    def items(self):
+        return self.data.items()
+
+    has_key = __contains__
 
 class LayoutFactory(object):
 

Modified: cpsskins/branches/jmo-perspectives/engines/default/formats/style.py
==============================================================================
--- cpsskins/branches/jmo-perspectives/engines/default/formats/style.py 
(original)
+++ cpsskins/branches/jmo-perspectives/engines/default/formats/style.py Tue Dec 
13 15:27:06 2005
@@ -17,7 +17,8 @@
 """
 __docformat__ = "reStructuredText"
 
-from persistent.mapping import PersistentMapping
+from BTrees.OOBTree import OOBTree
+from persistent import Persistent
 
 from zope.component.interfaces import IFactory
 from zope.interface import implements, implementedBy
@@ -37,7 +38,7 @@
 
 IStyle.setTaggedValue('name', u'style')
 
-class Style(Format, PersistentMapping):
+class Style(Format, Persistent):
     """A style is a collection of properties
 
     >>> s = Style()
@@ -99,16 +100,9 @@
 
     implements(IStyle)
 
-    __super_delitem = PersistentMapping.__delitem__
-    __super_setitem = PersistentMapping.__setitem__
-    __super_getitem = PersistentMapping.__getitem__
-    __super_items = PersistentMapping.items
-    __super_get = PersistentMapping.get
-    __super_keys = PersistentMapping.keys
-
     def __init__(self, **kw):
         super(Style, self).__init__(**kw)
-        self.data = PersistentMapping()
+        self.data = OOBTree()
 
     def __repr__(self):
         return "<Style of type: %s>" % self.type
@@ -124,7 +118,7 @@
         return k
 
     def __getitem__(self, k):
-        return self.__super_getitem(self._wrap(k))
+        return self.data[self._wrap(k)]
 
     def __setitem__(self, k, v):
         if not isinstance(v, dict):
@@ -133,25 +127,28 @@
         if k in self:
             del self[k]
         if v:
-            self.__super_setitem(self._wrap(k), v)
+            self.data[self._wrap(k)] = v
 
     def __delitem__(self, k):
-        return self.__super_delitem(self._wrap(k))
+        del self.data[self._wrap(k)]
 
     def __iter__(self):
         return iter(self.data)
 
     def keys(self):
-        return [self._unwrap(k) for k in self.__super_keys()]
+        return [self._unwrap(k) for k in self.data.keys()]
 
     def items(self):
-        return [(self._unwrap(k), v) for k, v in self.__super_items()]
+        return [(self._unwrap(k), self[k]) for k in self]
 
     def has_key(self, k):
-        return k in self.keys()
+        return self._wrap(k) in self.data.keys()
 
     def get(self, k, default=None):
-        return self.__super_get(self._wrap(k), default)
+        return self.data.get(self._wrap(k), default)
+
+    def __len__(self):
+        return len(self.data)
 
     __contains__ = has_key
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to