Module XMLRPCClient
[hide private]
[frames] | no frames]

Source Code for Module XMLRPCClient

 1  #XMLRPCClient.py 
 2  #A class to communicate with a server XML-RPC for import/export of automata 
 3  #Author: Matteo Cantarelli 
 4  #E-mail: matteo.cantarelli@lurpa.ens-cachan.fr 
 5  #Release: 0.2.6 
 6   
 7  import xmlrpclib 
 8  import xml.sax.saxutils 
 9  import urllib 
10   
11  DECODE={ 
12           '"':'\"',     #quote 
13           '
':'',        #carriage return 
14           '
':'\n',      #newline 
15           '	':'\t',       #tabulation 
16           '/':'/',       #slash 
17          } 
18   
19  DEFAULT_SERVER='http://127.0.0.1'    #the default server, Supremica is running on local 
20  DEFAULT_PORT='9112'                  #the default port for Supremica is the 9112 
21   
22 -class CXMLRPCClient(object):
23 "This class implements an XML RPC Client"
24 - def __init__(self,url=DEFAULT_SERVER+':'+DEFAULT_PORT):
25 """ 26 The constructor establish a connection to the given server. 27 28 @type url: string 29 @param url: the address of the XML RPC host. The port must be specified as well. If nothing is specified the connection is made to localhost on the Supremica default port 9112. 30 @return: void 31 """ 32 self.__server=xmlrpclib.Server(url)
33
34 - def uploadAutomata(self,filename):
35 """ 36 This method upload to the connected server the given XML file. 37 38 @type filename: string 39 @param filename: the filename to upload to the server 40 @return: void 41 """ 42 f=open(filename, 'r') 43 self.__server.addAutomata(str(f.read())) 44 f.close()
45
46 - def downloadAutomata(self,filename):
47 """ 48 This method download to the given file the automata present to the connected server. 49 50 @type filename: string 51 @param filename: the filename where to download the automata from the server 52 @return: void 53 """ 54 f=open(filename,'w') 55 56 v=[] 57 for x in self.__server.getAutomataIdentities(): 58 v.append(x.strip('\'')) #add the automaton's name after having stripped the quotes 59 60 f.write(xml.sax.saxutils.unescape(self.__server.getAutomata(v),DECODE)) 61 f.close()
62
63 - def downloadAutomaton(self,automaton,filename):
64 """ 65 This method download to the given file the given automaton present to the connected server. 66 67 @type filename: string 68 @param filename: the filename where to download the automaton from the server 69 @type automaton: string 70 @param automaton: the name of the automaton to download 71 @return: void 72 """ 73 f=open(filename,'w') 74 f.write(xml.sax.saxutils.unescape(self.__server.getAutomaton(automaton.strip('\'')),DECODE)) 75 f.close()
76