[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - OFSProperties.py:1.1 public.py:1.4
Shane Hathaway
shane@zope.com
Fri, 3 Jan 2003 17:04:55 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv20380/serial_ofs
Modified Files:
public.py
Added Files:
OFSProperties.py
Log Message:
Added PropertyManager support.
=== Added File Products/AdaptableStorage/serial_ofs/OFSProperties.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Aspect for OFS.PropertyManager properties.
$Id: OFSProperties.py,v 1.1 2003/01/03 22:04:22 shane Exp $
"""
from cPickle import dumps, loads
from mapper_public import IAspectSerializer, RowSequenceSchema
string_repr_types = {
'string': 1,
'float': 1,
'int': 1,
'long': 1,
'string': 1,
'date': 1,
'date_international': 1,
'text': 1,
'boolean': 1,
}
class OFSProperties:
__implements__ = IAspectSerializer
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
schema.addField('type', 'string')
schema.addField('data', 'string')
def getSchema(self):
return self.schema
def serialize(self, object, event):
res = []
assert object._properties is object._propertyMap()
event.ignoreAttribute('_properties')
for p in object._properties:
name = p['id']
t = p['type']
event.ignoreAttribute(name)
data = object.getProperty(name)
if t == 'lines':
v = '\n'.join(data)
elif string_repr_types.get(t):
v = str(data)
else:
v = dumps(data)
res.append((name, t, v))
return res
def deserialize(self, object, event, state):
assert object._properties is object._propertyMap()
old_props = object.propdict()
new_props = {}
for id, t, data in state:
p = old_props.get(id)
if p is None:
p = {'mode': 'wd'}
else:
p = p.copy()
p['id'] = id
p['type'] = t
new_props[id] = p
if old_props != new_props:
object._properties = tuple(new_props.values())
for id, t, v in state:
if t == 'lines':
data = v.split('\n')
elif string_repr_types.get(t):
data = str(v)
else:
data = loads(v)
object._updateProperty(id, data)
=== Products/AdaptableStorage/serial_ofs/public.py 1.3 => 1.4 ===
--- Products/AdaptableStorage/serial_ofs/public.py:1.3 Wed Dec 11 18:07:23 2002
+++ Products/AdaptableStorage/serial_ofs/public.py Fri Jan 3 17:04:22 2003
@@ -21,4 +21,4 @@
from FolderItemsByKeychain import FolderItemsByKeychain
from IdAttribute import IdAttribute
from MetaTypeClassifier import MetaTypeClassifier
-
+from OFSProperties import OFSProperties