[Zope-CVS] CVS: Products/AdaptableStorage/serial_std - AnyObjectSerializer.py:1.1 public.py:1.6

Shane Hathaway shane@zope.com
Mon, 9 Dec 2002 15:27:09 -0500


Update of /cvs-repository/Products/AdaptableStorage/serial_std
In directory cvs.zope.org:/tmp/cvs-serv10661/serial_std

Modified Files:
	public.py 
Added Files:
	AnyObjectSerializer.py 
Log Message:
Added two mappers to Zope2FS for serializing any kind of object.  If no mapper
is provided for a class, the database falls back to a default mapper--either
the "fileish" or the "folderish" mapper.

... which is *really cool*. :-)  I've been trying to achieve this in a clean
way for months.  (Deeeeep, loooonnnnnggggg sigh of relief!)



=== Added File Products/AdaptableStorage/serial_std/AnyObjectSerializer.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 of any persistent object

$Id: AnyObjectSerializer.py,v 1.1 2002/12/09 20:27:09 shane Exp $
"""

from serial_public import ObjectSerializer


class AnyObjectSerializer (ObjectSerializer):

    __implements__ = ObjectSerializer.__implements__

    def __init__(self):
        self._aspects = []  # [(name, aspect)] -- Order matters.

    def canSerialize(self, object):
        return 1

    def createEmptyInstance(self, classification=None):
        if classification is None:
            # This serializer can't do anything without the classification.
            return None
        cn = classification['class_name']
        module, name = cn.split(':', 1)
        m = __import__(module, {}, {}, ('__doc__',))
        c = getattr(m, name)
        return c.__basicnew__()



=== Products/AdaptableStorage/serial_std/public.py 1.5 => 1.6 ===
--- Products/AdaptableStorage/serial_std/public.py:1.5	Mon Dec  9 13:25:29 2002
+++ Products/AdaptableStorage/serial_std/public.py	Mon Dec  9 15:27:09 2002
@@ -16,6 +16,7 @@
 $Id$
 """
 
+from AnyObjectSerializer import AnyObjectSerializer
 from FixedClassifier import FixedClassifier
 from FixedPersistentMapping import FixedPersistentMapping
 from FullState import FullState