]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader/Test/xmlrun_orig.sh
Salome HOME
CMake:
[modules/yacs.git] / src / yacsloader / Test / xmlrun_orig.sh
1 #!/usr/bin/env python
2 # Copyright (C) 2006-2013  CEA/DEN, EDF R&D
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.
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 import xmlrpclib,sys
22
23 #example
24 data="""
25 <methodCall>
26   <methodName>echo</methodName>
27   <params>
28     <param><value>hello, world</value></param>
29     <param><value><double>3.5</double></value></param>
30     <param><value><string>coucou</string></value></param>
31   </params>
32 </methodCall>
33 """
34 def echo(args):
35   print "args=",args
36   if not args:
37     return None
38   elif len(args) == 1:
39     return args[0]
40   else:
41     return args
42
43 f=open("input")
44 data=f.read()
45 f.close()
46 print data
47
48 class Objref:
49   """Wrapper for objrefs """
50   def __init__(self,data=None):
51     self.data=data
52   def __str__(self):
53     return self.data or ""
54   def __cmp__(self, other):
55     if isinstance(other, Binary):
56       other = other.data
57     return cmp(self.data, other)
58
59   def decode(self, data):
60     self.data = data
61
62   def encode(self, out):
63     out.write("<value><objref>")
64     out.write(self.data or "")
65     out.write("</objref></value>\n")
66
67 xmlrpclib.WRAPPERS=xmlrpclib.WRAPPERS+(Objref,)
68
69 def end_objref(self,data):
70   self.append(Objref(data))
71   self._value=0
72
73 xmlrpclib.Unmarshaller.end_objref=end_objref
74 xmlrpclib.Unmarshaller.dispatch["objref"]=end_objref
75
76 params, method = xmlrpclib.loads(data)
77
78 try:
79    call=eval(method)
80    response=call(params)
81    response = (response,)
82 except:
83    # report exception back to server
84    response = xmlrpclib.dumps( xmlrpclib.Fault(1, "%s:%s" % sys.exc_info()[:2]))
85 else:
86    response = xmlrpclib.dumps( response, methodresponse=1)
87
88 print response
89 f=open("output",'w')
90 f.write(response)
91 f.close()