[CMF-checkins] SVN: CMF/trunk/GenericSetup/ Don't export or purge read-only properties.

Florent Guillaume fg at nuxeo.com
Wed Dec 28 19:45:50 EST 2005


Log message for revision 41049:
  Don't export or purge read-only properties.

Changed:
  U   CMF/trunk/GenericSetup/CHANGES.txt
  U   CMF/trunk/GenericSetup/tests/test_utils.py
  U   CMF/trunk/GenericSetup/utils.py

-=-
Modified: CMF/trunk/GenericSetup/CHANGES.txt
===================================================================
--- CMF/trunk/GenericSetup/CHANGES.txt	2005-12-29 00:02:42 UTC (rev 41048)
+++ CMF/trunk/GenericSetup/CHANGES.txt	2005-12-29 00:45:49 UTC (rev 41049)
@@ -11,6 +11,10 @@
     - Forward ported changes from GenericSetup 0.11 and 0.12 (which were
       created in a separate repository).
 
+    - Don't export or purge read-only properties.
+
+    - Correctly quote XML on export.
+
   GenericSetup 1.0 (2005/09/23)
 
     - CVS tag:  GenericSetup-1_0

Modified: CMF/trunk/GenericSetup/tests/test_utils.py
===================================================================
--- CMF/trunk/GenericSetup/tests/test_utils.py	2005-12-29 00:02:42 UTC (rev 41048)
+++ CMF/trunk/GenericSetup/tests/test_utils.py	2005-12-29 00:45:49 UTC (rev 41049)
@@ -210,6 +210,8 @@
         obj._setProperty('foo_selection', 'foobarbaz', 'selection')
         obj._setProperty('foo_mselection', 'foobarbaz', 'multiple selection')
         obj._setProperty('foo_boolean0', '', 'boolean')
+        obj._setProperty('foo_ro', '', 'string')
+        obj._properties[-1]['mode'] = '' # Read-only, not exported or purged
         self.helpers = self._makeOne(obj, DummySetupEnviron())
 
     def _populate(self, obj):
@@ -225,6 +227,7 @@
         obj._updateProperty('foo_selection', 'Foo')
         obj._updateProperty( 'foo_mselection', ('Foo', 'Baz') )
         obj.foo_boolean0 = 0
+        obj._updateProperty('foo_ro', 'RO')
 
     def test__extractProperties_empty(self):
         doc = self.helpers._doc = PrettyDocument()
@@ -243,6 +246,25 @@
 
         self.assertEqual(doc.toprettyxml(' '), _NORMAL_PROPERTY_EXPORT)
 
+    def test__purgeProperties(self):
+        obj = self.helpers.context
+        self._populate(obj)
+        self.helpers._purgeProperties()
+
+        self.assertEqual(getattr(obj, 'foo_boolean', None), None)
+        self.assertEqual(getattr(obj, 'foo_date', None), None)
+        self.assertEqual(getattr(obj, 'foo_float', None), None)
+        self.assertEqual(getattr(obj, 'foo_int', None), None)
+        self.assertEqual(getattr(obj, 'foo_lines', None), None)
+        self.assertEqual(getattr(obj, 'foo_long', None), None)
+        self.assertEqual(getattr(obj, 'foo_string', None), None)
+        self.assertEqual(getattr(obj, 'foo_text', None), None)
+        self.assertEqual(getattr(obj, 'foo_tokens', None), None)
+        self.assertEqual(getattr(obj, 'foo_selection', None), None)
+        self.assertEqual(getattr(obj, 'foo_mselection', None), None)
+        self.assertEqual(getattr(obj, 'foo_boolean0', None), None)
+        self.assertEqual(getattr(obj, 'foo_ro', None), 'RO')
+
     def test__initProperties_normal(self):
         node = parseString(_NORMAL_PROPERTY_EXPORT).documentElement
         self.helpers._initProperties(node)

Modified: CMF/trunk/GenericSetup/utils.py
===================================================================
--- CMF/trunk/GenericSetup/utils.py	2005-12-29 00:02:42 UTC (rev 41048)
+++ CMF/trunk/GenericSetup/utils.py	2005-12-29 00:45:49 UTC (rev 41049)
@@ -593,11 +593,15 @@
         fragment = self._doc.createDocumentFragment()
 
         for prop_map in self.context._propertyMap():
-            if prop_map['id'] == 'i18n_domain':
+            prop_id = prop_map['id']
+            if prop_id == 'i18n_domain':
                 continue
+
+            # Don't export read-only nodes
+            if 'w' not in prop_map.get('mode', 'wd'):
+                continue
+
             node = self._doc.createElement('property')
-
-            prop_id = prop_map['id']
             node.setAttribute('name', prop_id)
 
             prop = self.context.getProperty(prop_id)
@@ -630,8 +634,11 @@
 
     def _purgeProperties(self):
         for prop_map in self.context._propertyMap():
+            mode = prop_map.get('mode', 'wd')
+            if 'w' not in mode:
+                continue
             prop_id = prop_map['id']
-            if 'd' in prop_map.get('mode', 'wd') and not prop_id == 'title':
+            if 'd' in mode and not prop_id == 'title':
                 self.context._delProperty(prop_id)
             else:
                 if prop_map.get('type') == 'multiple selection':



More information about the CMF-checkins mailing list