1 # Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # File : salome_pynode.py
21 # Author : Christian CAREMOLI, EDF
26 When imported this module adds to CORBA proxy (from PyNode type) automatic pickle and unpickle
27 of arguments and results when calling execute method. It also converts the SALOME exception into a standard python
35 class SmartPyNode(Engines._objref_PyNode):
37 Engines._objref_PyNode.__init__(self)
39 def execute(self,functionName,*args,**kws):
41 args=cPickle.dumps((args,kws),-1)
42 results=Engines._objref_PyNode.execute(self,functionName,args)
43 x=cPickle.loads(results)
45 except SALOME.SALOME_Exception, e:
46 raise ValueError(e.details.text)
48 def __getattr__(self,name):
49 """ a trick to be able to call directly a remote method by its name : no need to use execute"""
51 raise AttributeError, name
52 def afunc(*args,**kws):
53 return self.execute(name,*args,**kws)
56 class SmartPyScriptNode(Engines._objref_PyScriptNode):
58 Engines._objref_PyScriptNode.__init__(self)
60 def execute(self,outargsname,*args,**kws):
61 #the tuple args are ignored
63 args=cPickle.dumps(((),kws),-1)
64 results=Engines._objref_PyScriptNode.execute(self,outargsname,args)
65 x=cPickle.loads(results)
67 except SALOME.SALOME_Exception, e:
68 raise ValueError(e.details.text)
70 #Register the new proxy for PyNode
71 omniORB.registerObjref(Engines._objref_PyNode._NP_RepositoryId, SmartPyNode)
72 #Register the new proxy for PyScriptNode
73 omniORB.registerObjref(Engines._objref_PyScriptNode._NP_RepositoryId, SmartPyScriptNode)