1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 ## \defgroup salome_kernel salome.kernel
23 # \details Package containing the KERNEL python utilities
24 # \defgroup deprecation
28 # \defgroup uiexception
29 # \defgroup datamodeler
33 # \defgroup unittester
34 # \defgroup pyunittester
37 __all__ = [ "deprecation", "logger", "termcolor", "logconfig" ]
38 __version__ = "@SALOMEKERNEL_GIT_SHA1@"
40 # WARN: This file SHOULD NOT import salome stuff so that modules of the
41 # package could be used outside of a SALOME session context when
42 # possible. For example logger.py, datamodeler.py, enumerate.py,
43 # diclookup.py, ... does not need a SALOME running application.
46 # ==============================================================================
47 # Generic serialization functions for the module datamodeler
48 # ==============================================================================
52 def serialize(dataToSerialize):
54 Creates a string description of the specified data.
55 .. attribute:: dataToSerialize
56 a data object to serialize
58 serialstring = pickle.dumps(dataToSerialize)
61 def unserialize(stringToUnserialize):
63 Creates a data object from its string description. The string description
64 is supposed to be obtained by a call to serialize.
65 .. attribute:: stringToUnserialize
66 a string description of the object
68 data = pickle.loads(stringToUnserialize)
73 This class is used to create class-method (see MetaData)
75 def __init__(self, anycallable):
76 self.__call__ = anycallable
78 # ==============================================================================
79 # Basic use cases and unit tests
80 # ==============================================================================
83 def TEST_serialization():
84 from .testdata import TestData
85 ref_name = "my study case"
86 studyData = TestData()
87 studyData.setName(ref_name)
89 print("serialize data ...")
90 serialString = serialize(studyData)
91 print("unserialize data ...")
92 unserialData = unserialize(serialString)
94 res_name = unserialData.getName()
96 if ( ref_name != res_name ):
100 unserialData.setName("an other name")
104 if __name__ == "__main__":
105 from . import unittester
106 unittester.run("salome/kernel/__init__","TEST_serialization")