[Zope-CVS] CVS: Products/AdaptableStorage/serial_ofs - PythonScriptSerializer.py:1.2 ZSQLMethodSerializer.py:1.2 public.py:1.6
Shane Hathaway
shane@zope.com
Mon, 3 Feb 2003 13:27:23 -0500
Update of /cvs-repository/Products/AdaptableStorage/serial_ofs
In directory cvs.zope.org:/tmp/cvs-serv10265/serial_ofs
Modified Files:
public.py
Added Files:
PythonScriptSerializer.py ZSQLMethodSerializer.py
Log Message:
Integrated work by Christian Zagrodnick: added mappers for Python Scripts,
DTML Methods, DTML Documents, and ZSQLMethods. Thanks!
=== Products/AdaptableStorage/serial_ofs/PythonScriptSerializer.py 1.1 => 1.2 ===
--- /dev/null Mon Feb 3 13:27:23 2003
+++ Products/AdaptableStorage/serial_ofs/PythonScriptSerializer.py Mon Feb 3 13:26:50 2003
@@ -0,0 +1,61 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Aspect for a Python Script
+
+$Id$
+"""
+
+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')
+
+ def getSchema(self):
+ return self.schema
+
+ def canSerialize(self, object):
+ return isinstance(object, PythonScript)
+
+ def serialize(self, object, event):
+ assert isinstance(object, PythonScript)
+ data = object.read()
+ assert isinstance(data, StringType)
+ event.ignoreAttributes((
+ 'title', '_params', '_body', '_bind_names',
+ 'warnings', 'error', '_code', 'Python_magic',
+ 'Script_magic', 'func_defaults', 'func_code',
+ 'co_varnames', 'co_argcount',
+ ))
+ return data
+
+ def deserialize(self, object, event, state):
+ assert isinstance(state, StringType)
+ assert isinstance(object, PythonScript)
+ object.write(state)
+ object._makeFunction()
+
=== Products/AdaptableStorage/serial_ofs/ZSQLMethodSerializer.py 1.1 => 1.2 ===
--- /dev/null Mon Feb 3 13:27:23 2003
+++ Products/AdaptableStorage/serial_ofs/ZSQLMethodSerializer.py Mon Feb 3 13:26:50 2003
@@ -0,0 +1,130 @@
+##############################################################################
+#
+# 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.
+#
+##############################################################################
+"""Aspect for a Z SQL Method
+
+$Id$
+"""
+
+import re
+from types import StringType
+
+from Products.ZSQLMethods.SQL import SQL
+from Shared.DC.ZRDB.Aqueduct import parse
+
+try:
+ from IOBTree import Bucket
+except ImportError:
+ Bucket = lambda: {}
+
+from mapper_public import IAspectSerializer, FieldSchema, RowSequenceSchema
+
+
+class ZSQLMethodSerializer:
+ """Serializer for ZSQLMethods.
+
+ ZSQLMethodSerializer serializes using the same representation
+ as FTP or WebDAV. All computable attributes like compiled code
+ are dropped.
+ """
+
+ __implements__ = IAspectSerializer
+
+ schema = FieldSchema('data', 'string')
+
+ params_re = re.compile(r'\s*<params>(.*)</params>\s*\n', re.I | re.S)
+
+ def getSchema(self):
+ return self.schema
+
+ def canSerialize(self, object):
+ return isinstance(object, SQL)
+
+ def serialize(self, object, event):
+ data = object.document_src()
+ event.ignoreAttributes(('_arg', 'template', 'arguments_src', 'src'))
+ return data
+
+ def deserialize(self, object, event, state):
+ assert isinstance(state, StringType)
+ assert isinstance(object, SQL)
+ body = state
+ m = self.params_re.match(body)
+ if m:
+ object.arguments_src = m.group(1)
+ body = body[m.end():]
+ else:
+ object.arguments_src = ''
+ object._arg = parse(object.arguments_src)
+ object.src = body
+ object.template = object.template_class(body)
+ object.template.cook()
+ object._v_cache = ({}, Bucket())
+
+
+class ZSQLMethodPropertiesSerializer:
+ __implements__ = IAspectSerializer
+
+ schema = RowSequenceSchema()
+ schema.addField('id', 'string', 1)
+ schema.addField('type', 'string')
+ schema.addField('data', 'string')
+
+ attributes = {
+ 'title': str,
+ 'connection_id': str,
+ 'max_rows_': int,
+ 'max_cache_': int,
+ 'cache_time': int,
+ 'class_name_': str,
+ 'class_file_': str,
+ 'zclass': str, # XXX, what's that
+ 'allow_simple_one_argument_traversal': int,
+ 'connection_hook': str,
+ }
+
+ def getSchema(self):
+ return self.schema
+
+ def canSerialize(self, object):
+ return isinstance(object, SQL)
+
+ def serialize(self, object, event):
+ assert isinstance(object, SQL)
+ res = []
+ for attribute, factory in self.attributes.items():
+ if not hasattr(object, attribute):
+ continue
+ value = getattr(object, attribute)
+ t = factory.__name__
+ if value is None:
+ if factory in (int, long):
+ value = 0
+ else:
+ value = ''
+ value = str(value)
+ event.notifySerialized(attribute, value, 1)
+ res.append((attribute, t, value))
+ event.ignoreAttribute('_col')
+ return res
+
+ def deserialize(self, object, event, state):
+ assert isinstance(object, SQL)
+ for attribute, t, value in state:
+ factory = self.attributes.get(attribute)
+ if factory is None:
+ continue
+ value = factory(value)
+ setattr(object, attribute, value)
+ event.notifyDeserialized(attribute, value)
+
=== Products/AdaptableStorage/serial_ofs/public.py 1.5 => 1.6 ===
--- Products/AdaptableStorage/serial_ofs/public.py:1.5 Mon Jan 6 18:17:51 2003
+++ Products/AdaptableStorage/serial_ofs/public.py Mon Feb 3 13:26:50 2003
@@ -23,4 +23,7 @@
from MetaTypeClassifier import MetaTypeClassifier
from OFSProperties import OFSProperties
from UserFolderSerializer import UserFolderSerializer
+from PythonScriptSerializer import PythonScriptSerializer
+from ZSQLMethodSerializer import ZSQLMethodSerializer, \
+ ZSQLMethodPropertiesSerializer