[Zope-CVS] CVS: Products/Ape/lib/apelib/zope2 - products.py:1.1
apeconf.xml:1.13 ofsserial.py:1.16
Shane Hathaway
shane at zope.com
Fri Jul 23 22:36:16 EDT 2004
Update of /cvs-repository/Products/Ape/lib/apelib/zope2
In directory cvs.zope.org:/tmp/cvs-serv30523/lib/apelib/zope2
Modified Files:
apeconf.xml ofsserial.py
Added Files:
products.py
Log Message:
Fixed an issue with serializing DCWorkflow.ContainerTab instances.
ContainerTab needs the _mapping attribute initialized before
deserialization.
Also moved BTreeFolder2 serialization out of the main folder serializer
and created a "products" module for serializing products that
are very common yet not part of "core" Zope.
=== Added File Products/Ape/lib/apelib/zope2/products.py ===
##############################################################################
#
# Copyright (c) 2003 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.
#
##############################################################################
"""Serializers for Zope products
$Id: products.py,v 1.1 2004/07/24 02:36:16 shane Exp $
"""
from apelib.core.interfaces import ISerializer
from apelib.core.schemas import RowSequenceSchema
from apelib.zodb3.serializers import find_unmanaged
from apelib.zope2.ofsserial import FolderItems
class BTreeFolder2Items:
"""BTreeFolder2 items (de)serializer
"""
__implements__ = ISerializer
schema = RowSequenceSchema()
schema.add('key', 'string', 1)
schema.add('oid', 'string')
schema.add('classification', 'classification')
def can_serialize(self, obj):
return hasattr(obj, '_tree')
def serialize(self, event):
obj = event.obj
assert self.can_serialize(obj)
state = []
event.ignore('_objects')
d = obj._tree
event.ignore(('_tree', '_mt_index', '_count'))
for id in obj.objectIds():
base = d[id]
oid = event.obj_db.identify(base)
if oid is None:
oid = event.obj_db.new_oid()
event.referenced(id, base, True, oid)
# No need to pass classification.
state.append((id, oid, None))
# The structure that makes up the BTree (the root node and
# the buckets) are unmanaged. Tell the event about them.
event.upos.extend(find_unmanaged(obj._tree, obj._tree.values()))
return state
def deserialize(self, event, state):
obj = event.obj
if hasattr(obj, '_initBTrees'):
# Version 1.0.1+ of BTreeFolder2
obj._initBTrees()
else:
# Crufty workaround for older versions
obj.__init__(obj.id)
assert self.can_serialize(obj)
for (id, oid, classification) in state:
subob = event.resolve(id, oid, classification)
obj._setOb(id, subob)
# The tree and the buckets are unmanaged.
event.upos.extend(find_unmanaged(obj._tree, obj._tree.values()))
class ContainerTabItems (FolderItems):
"""DCWorkflow.ContainerTab items (de)serializer"""
def deserialize(self, event, state):
# This object needs a little help with initialization
event.obj._mapping = {}
FolderItems.deserialize(self, event, state)
=== Products/Ape/lib/apelib/zope2/apeconf.xml 1.12 => 1.13 ===
--- Products/Ape/lib/apelib/zope2/apeconf.xml:1.12 Fri Jul 23 04:37:35 2004
+++ Products/Ape/lib/apelib/zope2/apeconf.xml Fri Jul 23 22:36:16 2004
@@ -235,7 +235,7 @@
<store exact-class="AccessControl.User.UserFolder"
using="user_folder" />
-<!-- Mapper of ObjectManagers -->
+<!-- Arbitrary ObjectManagers -->
<mapper name="anyfolder" extends="folder"
class="OFS.ObjectManager.ObjectManager">
@@ -245,7 +245,7 @@
<store class="OFS.ObjectManager.ObjectManager"
using="anyfolder" />
-<!-- Mapper of SimpleItems -->
+<!-- Arbitrary SimpleItems -->
<mapper name="anyfile" extends="common_p"
class="OFS.SimpleItem.Item">
@@ -271,6 +271,26 @@
</mapper>
<store class="OFS.Application.Application" using="application" />
<load generic="basepath" using="application" />
+
+<!-- BTreeFolder2 and derivatives -->
+
+<mapper name="btreefolder2" extends="folder"
+ class="Products.BTreeFolder2.BTreeFolder2.BTreeFolder2">
+ <serializer name="items"
+ factory="apelib.zope2.products.BTreeFolder2Items" />
+</mapper>
+<store class="Products.BTreeFolder2.BTreeFolder2.BTreeFolder2"
+ using="btreefolder2" />
+
+<!-- DCWorkflow.ContainerTab -->
+
+<mapper name="containertab" extends="folder"
+ class="Products.DCWorkflow.ContainerTab.ContainerTab">
+ <serializer name="items"
+ factory="apelib.zope2.products.ContainerTabItems" />
+</mapper>
+<store class="Products.DCWorkflow.ContainerTab.ContainerTab"
+ using="containertab" />
<!-- Compatibility with former mapper names. -->
=== Products/Ape/lib/apelib/zope2/ofsserial.py 1.15 => 1.16 ===
--- Products/Ape/lib/apelib/zope2/ofsserial.py:1.15 Thu Jul 22 01:53:26 2004
+++ Products/Ape/lib/apelib/zope2/ofsserial.py Fri Jul 23 22:36:16 2004
@@ -17,7 +17,7 @@
"""
from cPickle import dumps, loads
-from types import DictType, StringType
+from types import DictType
from Acquisition import aq_base
from OFS.SimpleItem import Item_w__name__
@@ -28,7 +28,6 @@
from apelib.core.interfaces import ISerializer, SerializationError
from apelib.core.schemas import ColumnSchema, RowSequenceSchema
from apelib.core.serializers import OptionalSerializer
-from apelib.zodb3.serializers import find_unmanaged
string_repr_types = {
@@ -88,21 +87,12 @@
def can_serialize(self, obj):
return isinstance(obj, ObjectManager)
- def _is_a_btree_folder(self, ob):
- # Maybe this should use isinstance(), but then Ape
- # would depend on the BTreeFolder2 product.
- return hasattr(ob, '_tree') and hasattr(ob, '_mt_index')
-
def serialize(self, event):
obj = event.obj
assert isinstance(obj, ObjectManager), repr(obj)
state = []
event.ignore('_objects')
d = obj.__dict__
- btree_folder = self._is_a_btree_folder(obj)
- if btree_folder:
- d = obj._tree
- event.ignore(('_tree', '_mt_index', '_count'))
for id in obj.objectIds():
if d.has_key(id):
base = d[id]
@@ -115,34 +105,18 @@
event.referenced(id, base, True, oid)
# No need to pass classification.
state.append((id, oid, None))
- if btree_folder:
- # The structure that makes up the BTree (the root node and
- # the buckets) are unmanaged. Tell the event about them.
- event.upos.extend(find_unmanaged(obj._tree, obj._tree.values()))
return state
def deserialize(self, event, state):
obj = event.obj
assert isinstance(obj, ObjectManager), obj
- btree_folder = self._is_a_btree_folder(obj)
- if btree_folder:
- if hasattr(obj, '_initBTrees'):
- # Version 1.0.1+ of BTreeFolder2
- obj._initBTrees()
- else:
- # Crufty workaround for older versions
- obj.__init__(obj.id)
for (id, oid, classification) in state:
subob = event.resolve(id, oid, classification)
obj._setOb(id, subob)
- if not btree_folder:
- obj._objects += ({
- 'id': id,
- 'meta_type': subob.__class__.meta_type,
- },)
- if btree_folder:
- # The tree and the buckets are unmanaged.
- event.upos.extend(find_unmanaged(obj._tree, obj._tree.values()))
+ obj._objects += ({
+ 'id': id,
+ 'meta_type': subob.__class__.meta_type,
+ },)
class IdAttribute:
More information about the Zope-CVS
mailing list