]> SALOME platform Git repositories - modules/kernel.git/blob - src/KERNEL_PY/omnipatch.py
Salome HOME
PR: Corrections from C. Caremoli, for embedded python.
[modules/kernel.git] / src / KERNEL_PY / omnipatch.py
1 # Copyright (C) 2005  OPEN CASCADE, CEA, EDF R&D, LEG
2 #           PRINCIPIA R&D, EADS CCR, Lip6, BV, CEDRAT
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either 
6 # version 2.1 of the License.
7
8 # This library is distributed in the hope that it will be useful 
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
11 # Lesser General Public License for more details.
12
13 # You should have received a copy of the GNU Lesser General Public  
14 # License along with this library; if not, write to the Free Software 
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18
19 """
20   This patch of omniORB is made to make it work with multiple interpreters
21   and to correct the problem of incomplete import of CORBA packages
22   in some situations common in SALOME
23
24   This patch add or modify functions in omniORB module.
25
26   In multiple interpreters context, omniORB module is meant to be shared among
27   all interpreters
28 """
29 import sys,string,imp
30 import omniORB
31 # Map of partially-opened modules
32 _partialModules = {}
33 # Map of modules to share
34 shared_imported={}
35
36 # Function to return a Python module for the required IDL module name
37 def openModule(mname, fname=None):
38     # Salome modification start
39     # Be sure to use the right module dictionnary
40     import sys
41     # Salome modification end
42
43     if mname == "CORBA":
44         mod = sys.modules["omniORB.CORBA"]
45         # Salome modification start
46         shared_imported[mname]=mod
47         # Salome modification end
48
49     elif sys.modules.has_key(mname):
50         mod = sys.modules[mname]
51
52         if _partialModules.has_key(mname):
53             pmod = _partialModules[mname]
54             mod.__dict__.update(pmod.__dict__)
55             del _partialModules[mname]
56         # Salome modification start
57         shared_imported[mname]=mod
58         # Salome modification end
59
60     elif _partialModules.has_key(mname):
61         mod = _partialModules[mname]
62
63     else:
64         mod = newModule(mname)
65
66
67     if not hasattr(mod, "__doc__") or mod.__doc__ is None:
68         mod.__doc__ = "omniORB IDL module " + mname + "\n\n" + \
69                       "Generated from:\n\n"
70
71     if fname is not None:
72         mod.__doc__ = mod.__doc__ + "  " + fname + "\n"
73
74     return mod
75
76 # Function to create a new module, and any parent modules which do not
77 # already exist
78 def newModule(mname):
79     # Salome modification start
80     # Be sure to use the right module dictionnary
81     import sys
82     # Salome modification end
83
84     mlist   = string.split(mname, ".")
85     current = ""
86     mod     = None
87
88     for name in mlist:
89         current = current + name
90
91         if sys.modules.has_key(current):
92             mod = sys.modules[current]
93
94         elif _partialModules.has_key(current):
95             mod = _partialModules[current]
96
97         else:
98             newmod = imp.new_module(current)
99             if mod: setattr(mod, name, newmod)
100             _partialModules[current] = mod = newmod
101
102         current = current + "."
103
104     return mod
105
106 # Function to update a module with the partial module store in the
107 # partial module map
108 def updateModule(mname):
109     # Salome modification start
110     # Be sure to use the right module dictionnary
111     import sys
112     # Salome modification end
113     if _partialModules.has_key(mname):
114         pmod = _partialModules[mname]
115         mod  = sys.modules[mname]
116         mod.__dict__.update(pmod.__dict__)
117         del _partialModules[mname]
118
119     # Salome modification start
120     shared_imported[mname]=sys.modules[mname]
121     # Salome modification end
122
123 omniORB.updateModule=updateModule
124 omniORB.newModule=newModule
125 omniORB.openModule=openModule
126