Salome HOME
copy tag mergefrom_BR_V0_1_CC_Salome_04oct07
[modules/yacs.git] / src / runtime / Test / xmlrun_orig.sh
1 #!/usr/bin/env python
2
3 import xmlrpclib,sys
4
5 data="""
6 <methodCall>
7   <methodName>echo</methodName>
8   <params>
9     <param><value>hello, world</value></param>
10     <param><value><double>3.5</double></value></param>
11     <param><value><string>coucou</string></value></param>
12   </params>
13 </methodCall>
14 """
15 def echo(args):
16   print args
17   return args
18
19 f=open("input")
20 data=f.read()
21 f.close()
22 print data
23
24 class Objref:
25   """Wrapper for objrefs """
26   def __init__(self,data=None):
27     self.data=data
28   def __str__(self):
29     return self.data or ""
30   def __cmp__(self, other):
31     if isinstance(other, Binary):
32       other = other.data
33     return cmp(self.data, other)
34
35   def decode(self, data):
36     self.data = data
37
38   def encode(self, out):
39     out.write("<value><objref>")
40     out.write(self.data or "")
41     out.write("</objref></value>\n")
42
43 xmlrpclib.WRAPPERS=xmlrpclib.WRAPPERS+(Objref,)
44
45 def end_objref(self,data):
46   self.append(Objref(data))
47   self._value=0
48
49 xmlrpclib.Unmarshaller.end_objref=end_objref
50 xmlrpclib.Unmarshaller.dispatch["objref"]=end_objref
51
52 params, method = xmlrpclib.loads(data)
53
54 try:
55    call=eval(method)
56    response=call(params)
57    response = (response,)
58 except:
59    # report exception back to server
60    response = xmlrpclib.dumps( xmlrpclib.Fault(1, "%s:%s" % sys.exc_info()[:2]))
61 else:
62    response = xmlrpclib.dumps( response, methodresponse=1)
63
64 print response
65 f=open("output",'w')
66 f.write(response)
67 f.close()