[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - OFSProperties.py:1.3

Shane Hathaway shane@zope.com
Tue, 21 Jan 2003 11:50:15 -0500


Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv28876/serial_ofs

Modified Files:
	OFSProperties.py 
Log Message:
Fixed storage of selection properties.  The select_variable was being forgotten.

=== Products/AdaptableStorage/serial_ofs/OFSProperties.py 1.2 => 1.3 ===
--- Products/AdaptableStorage/serial_ofs/OFSProperties.py:1.2	Mon Jan  6 10:36:50 2003
+++ Products/AdaptableStorage/serial_ofs/OFSProperties.py	Tue Jan 21 11:49:43 2003
@@ -17,6 +17,7 @@
 """
 
 from cPickle import dumps, loads
+from types import DictType
 
 from mapper_public import IAspectSerializer, RowSequenceSchema
 
@@ -65,7 +66,15 @@
             elif string_repr_types.get(t):
                 v = str(data)
             else:
-                v = dumps(data)
+                # Pickle the value and any extra info about the property.
+                # Extra info is present in select and multi-select properties.
+                d = p.copy()
+                del d['id']
+                del d['type']
+                if d.has_key('mode'):
+                    del d['mode']
+                d['value'] = data
+                v = dumps(d)
             res.append((name, t, v))
         return res
 
@@ -74,7 +83,7 @@
         assert object._properties is object._propertyMap()
         old_props = object.propdict()
         new_props = {}
-        for id, t, data in state:
+        for id, t, v in state:
             p = old_props.get(id)
             if p is None:
                 p = {'mode': 'wd'}
@@ -82,6 +91,15 @@
                 p = p.copy()
             p['id'] = id
             p['type'] = t
+            if v and not string_repr_types.get(t) and t != 'lines':
+                # v is a pickle.
+                # Check the pickle for extra property info.
+                d = loads(v)
+                if isinstance(d, DictType):
+                    del d['value']
+                    if d:
+                        # The data is stored with extra property info.
+                        p.update(d)
             new_props[id] = p
 
         if old_props != new_props:
@@ -92,7 +110,15 @@
                 data = v.split('\n')
             elif string_repr_types.get(t):
                 data = str(v)
+            elif v:
+                d = loads(v)
+                if isinstance(d, DictType):
+                    # The data is stored with extra property info.
+                    data = d['value']
+                else:
+                    data = d
             else:
-                data = loads(v)
+                # Fall back to a default.
+                data = ''
             object._updateProperty(id, data)