]> SALOME platform Git repositories - modules/kernel.git/blob - src/KERNEL_PY/kernel/__init__.py
Salome HOME
bos #42937: [CEA 41954] Integration of UB24.04 patches
[modules/kernel.git] / src / KERNEL_PY / kernel / __init__.py
1 # -*- coding: iso-8859-1 -*-
2 # Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 ## \defgroup salome_kernel salome.kernel
22 #  \{ 
23 #  \details Package containing the KERNEL python utilities
24 #  \defgroup deprecation
25 #  \defgroup termcolor
26 #  \defgroup logger
27 #  \defgroup enumerate
28 #  \defgroup uiexception
29 #  \defgroup datamodeler
30 #  \defgroup diclookup
31 #  \defgroup service
32 #  \defgroup studyedit
33 #  \defgroup unittester
34 #  \defgroup pyunittester
35 #  \}
36
37 __all__ = [ "deprecation", "logger", "termcolor", "logconfig" ]
38 __version__ = "@SALOMEKERNEL_GIT_SHA1@"
39 __config_datetime__ = "@SALOMEKERNEL_CONFIG_TIME@"
40
41 # WARN: This file SHOULD NOT import salome stuff so that modules of the
42 # package could be used outside of a SALOME session context when
43 # possible. For example logger.py, datamodeler.py, enumerate.py,
44 # diclookup.py, ... does not need a SALOME running application.
45
46 #
47 # ==============================================================================
48 # Generic serialization functions for the module datamodeler
49 # ==============================================================================
50 #
51 import pickle
52
53 def serialize(dataToSerialize):
54     """
55     Creates a string description of the specified data.
56     .. attribute:: dataToSerialize
57     a data object to serialize
58     """
59     serialstring = pickle.dumps(dataToSerialize)
60     return serialstring
61
62 def unserialize(stringToUnserialize):
63     """
64     Creates a data object from its string description. The string description
65     is supposed to be obtained by a call to serialize.
66     .. attribute:: stringToUnserialize
67     a string description of the object
68     """
69     data = pickle.loads(stringToUnserialize)
70     return data
71
72 class Callable:
73     """
74     This class is used to create class-method (see MetaData)
75     """
76     def __init__(self, anycallable):
77         self.__call__ = anycallable
78 #
79 # ==============================================================================
80 # Basic use cases and unit tests
81 # ==============================================================================
82 #
83
84 def TEST_serialization():
85     from .testdata import TestData
86     ref_name = "my study case"
87     studyData = TestData()
88     studyData.setName(ref_name)
89
90     print("serialize data ...")
91     serialString = serialize(studyData)
92     print("unserialize data ...")
93     unserialData = unserialize(serialString)
94
95     res_name = unserialData.getName()
96     print(res_name)
97     if ( ref_name != res_name ):
98         return False
99
100     unserialData.log()
101     unserialData.setName("an other name")
102
103     return True
104
105 if __name__ == "__main__":
106     from . import unittester
107     unittester.run("salome/kernel/__init__","TEST_serialization")