Author: jmorliaguet
Date: Sun Jun 18 17:55:29 2006
New Revision: 3451

Modified:
   cpsskins/branches/paris-sprint-2006/locations/README.txt
   cpsskins/branches/paris-sprint-2006/storage/locations.py
   cpsskins/branches/paris-sprint-2006/storage/relations.py
   cpsskins/branches/paris-sprint-2006/storage/storage.py

Log:

- fixed the storages' __setitem__, __delitem__

- we store location paths as tuples to avoid extra conversions

- the relation storage still uses a BTreeContainer mix-in (can be optimized)



Modified: cpsskins/branches/paris-sprint-2006/locations/README.txt
==============================================================================
--- cpsskins/branches/paris-sprint-2006/locations/README.txt    (original)
+++ cpsskins/branches/paris-sprint-2006/locations/README.txt    Sun Jun 18 
17:55:29 2006
@@ -172,8 +172,8 @@
 
     >>> from pprint import pprint
     >>> pprint(dict(locations))
-    {u'f1': <Location at: f1 ('folder 1')>,
-     u'f1/f2': <Location at: f1/f2 ('folder 1/2')>}
+    {(u'f1',): <Location at: f1 ('folder 1')>,
+     (u'f1', 'f2'): <Location at: f1/f2 ('folder 1/2')>}
 
 now we want to find the location of 'f1/f2/f3':
 

Modified: cpsskins/branches/paris-sprint-2006/storage/locations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/locations.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/locations.py    Sun Jun 18 
17:55:29 2006
@@ -42,7 +42,7 @@
     implements(ILocationStorage)
 
     def add(self, location, name=u''):
-        path = str(location)
+        path = location.path
         if path in self:
             del self[path]
         self[path] = location
@@ -51,18 +51,19 @@
         if not isinstance(locations, list):
             locations = [locations]
         for location in locations:
-            if str(location) not in self:
+            if location.path not in self:
                 continue
-            del self[str(location)]
+            del self[location.path]
 
     def find(self, path):
+        if isinstance(path, basestring):
+            path = tuple(path.split(u'/'))
         if path in self:
             return self[path]
 
-        spath = path.split(u'/')
-        spath_len = len(spath)
-        for i in range(spath_len):
-            p = u'/'.join(spath[0:spath_len-i])
+        path_len = len(path)
+        for i in range(path_len):
+            p = path[0:path_len-i]
             if p in self:
                 return self[p]
         return None

Modified: cpsskins/branches/paris-sprint-2006/storage/relations.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/relations.py    (original)
+++ cpsskins/branches/paris-sprint-2006/storage/relations.py    Sun Jun 18 
17:55:29 2006
@@ -79,7 +79,7 @@
     def __delitem__(item):
         """ """
 
-class RelationStorage(Storage):
+class RelationStorage(BTreeContainer, Storage):
     """A BTree-based relation container with a relation indexer.
 
     >>> from zope.interface.verify import verifyClass

Modified: cpsskins/branches/paris-sprint-2006/storage/storage.py
==============================================================================
--- cpsskins/branches/paris-sprint-2006/storage/storage.py      (original)
+++ cpsskins/branches/paris-sprint-2006/storage/storage.py      Sun Jun 18 
17:55:29 2006
@@ -18,7 +18,8 @@
 __docformat__ = "reStructuredText"
 
 import re
-from zope.app.container.btree import BTreeContainer
+from BTrees.OOBTree import OOBTree
+from zope.app.container.sample import SampleContainer
 from zope.app.container.contained import Contained
 from zope.app.container.contained import ObjectAddedEvent
 from zope.app.container.interfaces import INameChooser
@@ -32,7 +33,7 @@
 from cpsskins.storage.interfaces import IStorage
 from cpsskins.utils import cloneObject
 
-class Storage(BTreeContainer, Contained):
+class Storage(SampleContainer, Contained):
     """A base storage class.
 
     >>> from zope.interface.verify import verifyClass
@@ -42,11 +43,9 @@
     """
     implements(IStorage)
 
-    __btree__setitem__ = BTreeContainer.__setitem__
-    __btree__delitem__ = BTreeContainer.__delitem__
-
     def __init__(self, **kw):
         super(Storage, self).__init__()
+        self._SampleContainer__data = OOBTree()
 
     def add(self, object, name=u''):
         """Add an object to the storage.
@@ -95,11 +94,11 @@
         self.remove(list(self))
 
     def __setitem__(self, key, object):
-        self.__btree__setitem__(key, object)
+        self._SampleContainer__data[key] = object
         self._p_changed = True
 
     def __delitem__(self, key):
-        self.__btree__delitem__(key)
+        del self._SampleContainer__data[key]
         self._p_changed = True
 
 
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to