[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - UserFolderSerializer.py:1.2.2.1 FilePData.py:1.2.2.1 FolderItems.py:1.9.2.1 FolderItemsByKeychain.py:1.2.2.1 IdAttribute.py:1.3.2.1 OFSProperties.py:1.1.2.1
Christian Zagrodnick
cz@gocept.com
Mon, 13 Jan 2003 14:46:32 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv23160
Modified Files:
Tag: zagy-patches
FilePData.py FolderItems.py FolderItemsByKeychain.py
IdAttribute.py OFSProperties.py
Added Files:
Tag: zagy-patches
UserFolderSerializer.py
Log Message:
merging HEAD into zagy-patches branch
=== Added File Products/AdaptableStorage/serial_ofs/UserFolderSerializer.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.
#
##############################################################################
"""Serializer for a user folder.
This version lets the application keep a list of all users in RAM.
$Id: UserFolderSerializer.py,v 1.2.2.1 2003/01/13 19:46:29 zagy Exp $
"""
from AccessControl.User import User, UserFolder
from Persistence import PersistentMapping
from mapper_public import IAspectSerializer, RowSequenceSchema
class UserFolderSerializer:
__implements__ = IAspectSerializer
schema = RowSequenceSchema()
schema.addField('id', 'string', 1)
schema.addField('password', 'string')
schema.addField('roles', 'string:list')
schema.addField('domains', 'string:list')
def getSchema(self):
return self.schema
def canSerialize(self, object):
return isinstance(object, UserFolder)
def serialize(self, object, event):
assert isinstance(object, UserFolder), repr(object)
state = []
event.ignoreAttribute('data')
for id, user in object.data.items():
assert isinstance(user, User), repr(user)
assert len(user.__dict__.keys()) == 4, user.__dict__.keys()
state.append((id, user.__,
tuple(user.roles), tuple(user.domains)))
event.notifySerialized(id, user, 0)
event.addUnmanagedPersistentObjects([object.data])
event.addUnmanagedPersistentObjects(object.data.values())
return state
def deserialize(self, object, event, state):
assert isinstance(object, UserFolder)
object.data = PersistentMapping()
for id, password, roles, domains in state:
user = User(id, password, roles, domains)
object.data[id] = user
event.notifyDeserialized(id, user)
event.addUnmanagedPersistentObjects([object.data])
event.addUnmanagedPersistentObjects(object.data.values())
=== Products/AdaptableStorage/serial_ofs/FilePData.py 1.2 => 1.2.2.1 ===
--- Products/AdaptableStorage/serial_ofs/FilePData.py:1.2 Tue Dec 31 16:47:50 2002
+++ Products/AdaptableStorage/serial_ofs/FilePData.py Mon Jan 13 14:46:29 2003
@@ -18,6 +18,8 @@
from types import StringType
+from OFS.Image import File
+
from mapper_public import IAspectSerializer, FieldSchema
@@ -28,6 +30,9 @@
def getSchema(self):
return self.schema
+
+ def canSerialize(self, object):
+ return isinstance(object, File)
def serialize(self, object, event):
event.notifySerialized('data', object.data, 1)
=== Products/AdaptableStorage/serial_ofs/FolderItems.py 1.9 => 1.9.2.1 ===
--- Products/AdaptableStorage/serial_ofs/FolderItems.py:1.9 Tue Dec 31 16:47:50 2002
+++ Products/AdaptableStorage/serial_ofs/FolderItems.py Mon Jan 13 14:46:29 2003
@@ -23,7 +23,8 @@
from Acquisition import aq_base
from OFS.ObjectManager import ObjectManager
-from mapper_public import IAspectSerializer, RowSequenceSchema
+from mapper_public \
+ import IAspectSerializer, RowSequenceSchema, SerializationError
class FolderItems:
@@ -37,6 +38,9 @@
def getSchema(self):
return self.schema
+ def canSerialize(self, object):
+ return isinstance(object, ObjectManager)
+
def serialize(self, object, event):
assert isinstance(object, ObjectManager), repr(object)
state = []
@@ -44,14 +48,23 @@
for id, subob in object.objectItems():
base = aq_base(subob)
keychain = event.identifyObject(base)
- if keychain is None:
- keychain = event.makeKeychain(id, 0)
+ expected = event.makeKeychain(id, 0)
+ if keychain is not None and keychain != expected:
+ raise SerializationError(
+ "Subobject %s has unexpected keychain, %s. Expected %s." %
+ (repr(base), repr(keychain), repr(expected)))
+ keychain = expected
event.notifySerializedRef(id, base, 1, keychain)
state.append((id,))
+ event.ignoreAttribute('_use_fixed_oids_')
+ # Add a marker that tells the folder it has to move/rename
+ # in a special way. The _setOb patch sees this attribute.
+ object._use_fixed_oids_ = 1
return state
def deserialize(self, object, event, state):
assert isinstance(object, ObjectManager)
+ object._use_fixed_oids_ = 1
for (id,) in state:
keychain = event.makeKeychain(id, 0)
subob = event.dereference(id, keychain)
=== Products/AdaptableStorage/serial_ofs/FolderItemsByKeychain.py 1.2 => 1.2.2.1 ===
--- Products/AdaptableStorage/serial_ofs/FolderItemsByKeychain.py:1.2 Tue Dec 31 16:47:50 2002
+++ Products/AdaptableStorage/serial_ofs/FolderItemsByKeychain.py Mon Jan 13 14:46:29 2003
@@ -37,6 +37,9 @@
def getSchema(self):
return self.schema
+ def canSerialize(self, object):
+ return isinstance(object, ObjectManager)
+
def serialize(self, object, event):
assert isinstance(object, ObjectManager), repr(object)
state = []
=== Products/AdaptableStorage/serial_ofs/IdAttribute.py 1.3 => 1.3.2.1 ===
--- Products/AdaptableStorage/serial_ofs/IdAttribute.py:1.3 Tue Dec 31 16:47:50 2002
+++ Products/AdaptableStorage/serial_ofs/IdAttribute.py Mon Jan 13 14:46:29 2003
@@ -29,6 +29,9 @@
def getSchema(self):
return self.schema
+ def canSerialize(self, object):
+ return 1
+
def getAttrNameFor(self, object):
if isinstance(object, Item_w__name__):
return '__name__'
=== Products/AdaptableStorage/serial_ofs/OFSProperties.py 1.1 => 1.1.2.1 ===
--- Products/AdaptableStorage/serial_ofs/OFSProperties.py:1.1 Fri Jan 3 17:04:22 2003
+++ Products/AdaptableStorage/serial_ofs/OFSProperties.py Mon Jan 13 14:46:29 2003
@@ -20,6 +20,8 @@
from mapper_public import IAspectSerializer, RowSequenceSchema
+from OFS.PropertyManager import PropertyManager
+
string_repr_types = {
'string': 1,
@@ -45,8 +47,12 @@
def getSchema(self):
return self.schema
+ def canSerialize(self, object):
+ return isinstance(object, PropertyManager)
+
def serialize(self, object, event):
res = []
+ assert isinstance(object, PropertyManager), repr(object)
assert object._properties is object._propertyMap()
event.ignoreAttribute('_properties')
for p in object._properties:
@@ -64,6 +70,7 @@
return res
def deserialize(self, object, event, state):
+ assert isinstance(object, PropertyManager)
assert object._properties is object._propertyMap()
old_props = object.propdict()
new_props = {}