[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - PythonScriptSerializer.py:1.1.2.1
Christian Zagrodnick
cz@gocept.com
Mon, 13 Jan 2003 14:05:06 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv17557
Added Files:
Tag: zagy-patches
PythonScriptSerializer.py
Log Message:
Serializer for Python Scripts.
=== Added File Products/AdaptableStorage/serial_ofs/PythonScriptSerializer.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 a Python Script
$Id: PythonScriptSerializer.py,v 1.1.2.1 2003/01/13 19:05:04 zagy Exp $
"""
from types import StringType
from Products.PythonScripts.PythonScript import PythonScript
from mapper_public import IAspectSerializer, FieldSchema
class PythonScriptSerializer:
"""Serializer for PythonScripts.
PythonScriptSerializer serializes using the same representation
as FTP or WebDAV. All computable attributes like compiled code
is dropped.
"""
__implements__ = IAspectSerializer
schema = FieldSchema('data', 'string')
attributes = ('title', '_params', '_body', '_bind_names')
def getSchema(self):
return self.schema
def canSerialize(self, object):
return isinstance(object, PythonScript)
def serialize(self, object, event):
data = object.read()
assert isinstance(data, StringType)
for attr in self.attributes:
event.notifySerialized(attr, getattr(object, attr), 1)
for attr in ('warnings', 'error', '_code', 'Python_magic',
'Script_magic', 'func_defaults', 'func_code',
'co_varnames', 'co_argcount'):
event.ignoreAttribute(attr)
return data
def deserialize(self, object, event, state):
assert isinstance(state, StringType)
assert isinstance(object, PythonScript)
object.write(state)
for attr in self.attributes:
event.notifyDeserialized(attr, getattr(object, attr))
object._makeFunction()