1 # XMLRPC-specific code for SFA Client
6 # ServerException, ExceptionUnmarshaller
8 # Used to convert server exception strings back to an exception.
9 # from usenet, Raghuram Devarakonda
11 class ServerException(Exception):
14 class ExceptionUnmarshaller(xmlrpclib.Unmarshaller):
17 return xmlrpclib.Unmarshaller.close(self)
18 except xmlrpclib.Fault, e:
19 raise ServerException(e.faultString)
24 # A transport for XMLRPC that works on top of HTTPS
26 class XMLRPCTransport(xmlrpclib.Transport):
29 def make_connection(self, host):
30 # create a HTTPS connection object from a host descriptor
31 # host may be a string, or a (host, x509-dict) tuple
33 host, extra_headers, x509 = self.get_host_info(host)
35 HTTPS = httplib.HTTPS()
36 except AttributeError:
37 raise NotImplementedError(
38 "your version of httplib doesn't support HTTPS"
41 return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {}))
44 unmarshaller = ExceptionUnmarshaller()
45 parser = xmlrpclib.ExpatParser(unmarshaller)
46 return parser, unmarshaller
48 def get_server(url, key_file, cert_file, debug=False):
49 transport = XMLRPCTransport()
50 transport.key_file = key_file
51 transport.cert_file = cert_file
53 return xmlrpclib.ServerProxy(url, transport, allow_none=True, verbose=debug)