Back to index

salome-kernel  6.5.0
salome_pynode.py
Go to the documentation of this file.
00001 # Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 #
00003 # This library is free software; you can redistribute it and/or
00004 # modify it under the terms of the GNU Lesser General Public
00005 # License as published by the Free Software Foundation; either
00006 # version 2.1 of the License.
00007 #
00008 # This library is distributed in the hope that it will be useful,
00009 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 # Lesser General Public License for more details.
00012 #
00013 # You should have received a copy of the GNU Lesser General Public
00014 # License along with this library; if not, write to the Free Software
00015 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 #
00017 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 #
00019 
00020 #  File   : salome_pynode.py
00021 #  Author : Christian CAREMOLI, EDF
00022 #  Module : SALOME
00023 #  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/KERNEL_PY/Attic/salome_pynode.py,v 1.1.2.1.14.3.12.1 2012-04-12 14:05:13 vsr Exp $
00024 #
00025 """
00026  When imported this module adds to CORBA proxy (from PyNode type) automatic pickle and unpickle
00027  of arguments and results when calling execute method. It also converts the SALOME exception into a standard python
00028  exception
00029 """
00030 import omniORB
00031 import cPickle
00032 import SALOME
00033 import Engines
00034 
00035 class SmartPyNode(Engines._objref_PyNode):
00036   def __init__(self):
00037     Engines._objref_PyNode.__init__(self)
00038 
00039   def execute(self,functionName,*args,**kws):
00040     try:
00041       args=cPickle.dumps((args,kws),-1)
00042       results=Engines._objref_PyNode.execute(self,functionName,args)
00043       x=cPickle.loads(results)
00044       return x
00045     except SALOME.SALOME_Exception, e:
00046       raise ValueError(e.details.text)
00047 
00048   def __getattr__(self,name):
00049     """ a trick to be able to call directly a remote method by its name : no need to use execute"""
00050     if name[0]== '_':
00051       raise AttributeError, name
00052     def afunc(*args,**kws):
00053       return self.execute(name,*args,**kws)
00054     return afunc
00055 
00056 class SmartPyScriptNode(Engines._objref_PyScriptNode):
00057   def __init__(self):
00058     Engines._objref_PyScriptNode.__init__(self)
00059 
00060   def execute(self,outargsname,*args,**kws):
00061     #the tuple args are ignored
00062     try:
00063       args=cPickle.dumps(((),kws),-1)
00064       results=Engines._objref_PyScriptNode.execute(self,outargsname,args)
00065       x=cPickle.loads(results)
00066       return x
00067     except SALOME.SALOME_Exception, e:
00068       raise ValueError(e.details.text)
00069 
00070 #Register the new proxy for PyNode
00071 omniORB.registerObjref(Engines._objref_PyNode._NP_RepositoryId, SmartPyNode)
00072 #Register the new proxy for PyScriptNode
00073 omniORB.registerObjref(Engines._objref_PyScriptNode._NP_RepositoryId, SmartPyScriptNode)
00074