# XMLRPC-specific code for SFA Client import xmlrpclib ## # ServerException, ExceptionUnmarshaller # # Used to convert server exception strings back to an exception. # from usenet, Raghuram Devarakonda class ServerException(Exception): pass class ExceptionUnmarshaller(xmlrpclib.Unmarshaller): def close(self): try: return xmlrpclib.Unmarshaller.close(self) except xmlrpclib.Fault, e: raise ServerException(e.faultString) ## # XMLRPCTransport # # A transport for XMLRPC that works on top of HTTPS class XMLRPCTransport(xmlrpclib.Transport): key_file = None cert_file = None def make_connection(self, host): # create a HTTPS connection object from a host descriptor # host may be a string, or a (host, x509-dict) tuple import httplib host, extra_headers, x509 = self.get_host_info(host) try: HTTPS = httplib.HTTPS() except AttributeError: raise NotImplementedError( "your version of httplib doesn't support HTTPS" ) else: return httplib.HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file) #**(x509 or {})) def getparser(self): unmarshaller = ExceptionUnmarshaller() parser = xmlrpclib.ExpatParser(unmarshaller) return parser, unmarshaller def get_server(url, key_file, cert_file): transport = XMLRPCTransport() transport.key_file = key_file transport.cert_file = cert_file return xmlrpclib.ServerProxy(url, transport, allow_none=True)