If you don't want events, just use a BTree instead of a BTreeContainer.
I don't like persistent mappings as they are quite inefficient, everything is repickled when one item changes.


Florent

On 8 Dec 2005, at 21:15, [EMAIL PROTECTED] wrote:

Author: jmorliaguet
Date: Thu Dec  8 21:14:57 2005
New Revision: 1998

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

- we use a persistent mapping to store style properties instead of a BTree container to avoid triggering events when properties are added or removed.



Modified: cpsskins/branches/jmo-perspectives/engines/default/ filters/style/__init__.py ====================================================================== ======== --- cpsskins/branches/jmo-perspectives/engines/default/filters/ style/__init__.py (original) +++ cpsskins/branches/jmo-perspectives/engines/default/filters/ style/__init__.py Thu Dec 8 21:14:57 2005
@@ -108,23 +108,23 @@
from cpsskins.engines.default.formats.style import Style
s = Style()
s.identifier = '12345'
-    >>> s['div.body'] = {'color': 'red'}
+    >>> s[u'div.body'] = {'color': 'red'}

r = CSSRenderer(s)
r()
     u'div.body.style12345  {color:red}'

-    >>> s['ul'] = {'border': 'none', 'color': 'red'}
+    >>> s[u'ul'] = {'border': 'none', 'color': 'red'}
r = CSSRenderer(s)
r()
- u'div.body.style12345 {color:red}\\nul.style12345 {color:red;border:none}' + u'ul.style12345 {color:red;border:none}\ \ndiv.body.style12345 {color:red}'

-    >>> s['ul'] = {}
+    >>> s[u'ul'] = {}

-    >>> s[''] = {'color': 'red'}
+    >>> s[u''] = {'color': 'red'}
r = CSSRenderer(s)
r()
-    u'.style12345  {color:red}\\ndiv.body.style12345  {color:red}'
+    u'div.body.style12345  {color:red}\\n.style12345  {color:red}'

     """
     adapts(IStyle)

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 Thu Dec 8 21:14:57 2005
@@ -19,6 +19,8 @@

 from xml.dom.minidom import parseString

+from persistent.mapping import PersistentMapping
+
 from zope.app.container.btree import BTreeContainer
 from zope.app.publisher.browser import BrowserView
 from zope.component import adapts
@@ -35,11 +37,11 @@

 hasStyle = Predicate('_ has style _')

-class Style(Format, BTreeContainer):
+class Style(Format, PersistentMapping):
     """A style is a collection of properties

s = Style()
-    >>> s['div.body'] = {'color': 'red', 'border': 'none'}
+    >>> s[u'div.body'] = {'color': 'red', 'border': 'none'}

list(s.items())
     [(u'div.body', {'color': 'red', 'border': 'none'})]
@@ -50,10 +52,10 @@
len(s)
     1

-    >>> s.has_key('div.body')
+    >>> s.has_key(u'div.body')
     True

-    >>> s.has_key('div.box')
+    >>> s.has_key(u'div.box')
     False

list(s.keys())
@@ -61,52 +63,52 @@

s['span.item'] = {'font-style': 'red'}

-    >>> s.get('span.item')
+    >>> s.get(u'span.item')
     {'font-style': 'red'}

-    >>> del s['span.item']
+    >>> del s[u'span.item']
list(s.items())
     [(u'div.body', {'color': 'red', 'border': 'none'})]

-    >>> del s['div.body']
+    >>> del s[u'div.body']

     Empty key names must be allowed:

-    >>> s[''] = {'color': 'orange'}
+    >>> s[u''] = {'color': 'orange'}
list(s.keys())
     [u'']

list(s.items())
     [(u'', {'color': 'orange'})]

-    >>> '' in s
+    >>> u'' in s
     True

-    >>> s.has_key('')
+    >>> s.has_key(u'')
     True

-    >>> del s['']
+    >>> del s[u'']
list(s.items())
     []


-    >>> s['ul li'] = {}
-    >>> 'ul li' in s
+    >>> s[u'ul li'] = {}
+    >>> u'ul li' in s
     False
     """

     implements(IStyle)

-    __super_delitem = BTreeContainer.__delitem__
-    __super_getitem = BTreeContainer.__getitem__
-    __super_setitem = BTreeContainer.__setitem__
-    __super_keys = BTreeContainer.keys
-    __super_get = BTreeContainer.get
-    __super_items = BTreeContainer.items
-
-    def __init__(self, type='', id=''):
-        BTreeContainer.__init__(self)
-        Format.__init__(self, id=id)
+    __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, id=''):
+        super(Style, self).__init__(id=id)
+        self.data = PersistentMapping()

     def __repr__(self):
         return "Style('%s')" % self.id
@@ -146,7 +148,7 @@
         return k in self.keys()

     def get(self, k, default=None):
-        return self.__super_get(self._wrap(k), default=default)
+        return self.__super_get(self._wrap(k), default)

     __contains__ = has_key

--
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

--
Florent Guillaume, Nuxeo (Paris, France)   Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   [EMAIL PROTECTED]


--
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to