Back to index

plone3  3.1.7
base.py
Go to the documentation of this file.
00001 # Copyright (c) 2002-2006, Benjamin Saller <bcsaller@ideasuite.com>, and 
00002 #                      the respective authors.
00003 # All rights reserved.
00004 #
00005 # Redistribution and use in source and binary forms, with or without
00006 # modification, are permitted provided that the following conditions are
00007 # met:
00008 # 
00009 #     * Redistributions of source code must retain the above copyright
00010 #       notice, this list of conditions and the following disclaimer. 
00011 #     * Redistributions in binary form must reproduce the above
00012 #       copyright notice, this list of conditions and the following disclaimer
00013 #       in the documentation and/or other materials provided with the
00014 #       distribution. 
00015 #     * Neither the name of Archetypes nor the names of its contributors
00016 #       may be used to endorse or promote products derived from this software
00017 #       without specific prior written permission. 
00018 # 
00019 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00020 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00021 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00022 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00023 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00024 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00025 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00026 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00027 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00029 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 
00031 from Globals import InitializeClass
00032 from Acquisition import aq_base
00033 from AccessControl import ClassSecurityInfo
00034 from Products.Archetypes.interfaces.marshall import IMarshall
00035 from Products.Archetypes.interfaces.layer import ILayer
00036 
00037 class Marshaller:
00038     __implements__ = IMarshall, ILayer
00039 
00040     security = ClassSecurityInfo()
00041     security.declareObjectPrivate()
00042     security.setDefaultAccess('deny')
00043 
00044     def __init__(self, demarshall_hook=None, marshall_hook=None):
00045         self.demarshall_hook = demarshall_hook
00046         self.marshall_hook = marshall_hook
00047 
00048     def initializeInstance(self, instance, item=None, container=None):
00049         dm_hook = None
00050         m_hook = None
00051         if self.demarshall_hook is not None:
00052             dm_hook = getattr(instance, self.demarshall_hook, None)
00053         if self.marshall_hook is not None:
00054             m_hook = getattr(instance, self.marshall_hook, None)
00055         instance.demarshall_hook = dm_hook
00056         instance.marshall_hook = m_hook
00057 
00058     def cleanupInstance(self, instance, item=None, container=None):
00059         if hasattr(aq_base(instance), 'demarshall_hook'):
00060             delattr(instance, 'demarshall_hook')
00061         if hasattr(aq_base(instance), 'marshall_hook'):
00062             delattr(instance, 'marshall_hook')
00063 
00064     def demarshall(self, instance, data, **kwargs):
00065         raise NotImplemented
00066 
00067     def marshall(self, instance, **kwargs):
00068         raise NotImplemented
00069 
00070     def initializeField(self, instance, field):
00071         pass
00072 
00073     def cleanupField(self, instance, field):
00074         pass
00075 
00076 InitializeClass(Marshaller)