X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fclient%2Fsfaserverproxy.py;h=6c11ee0603779522fabef175bc46385c72e6f0ed;hb=2b8fb7af76b173ad4ad6583dbedbdf11a49f9549;hp=73aefc8c6d29c8b34afd0f8712ea25b566072017;hpb=0a9902d2a55a0a9ac03601345c4284293669012b;p=sfa.git diff --git a/sfa/client/sfaserverproxy.py b/sfa/client/sfaserverproxy.py index 73aefc8c..6c11ee06 100644 --- a/sfa/client/sfaserverproxy.py +++ b/sfa/client/sfaserverproxy.py @@ -1,14 +1,9 @@ # XMLRPC-specific code for SFA Client -# starting with 2.7.9 we need to turn off server verification -import ssl -try: - turn_off_server_verify = {'context': ssl._create_unverified_context()} -except: - turn_off_server_verify = {} +from sfa.util.ssl import simple_ssl_context -from sfa.util.py23 import xmlrpc_client -from sfa.util.py23 import http_client +import xmlrpc.client +import http.client try: from sfa.util.sfalogging import logger @@ -27,12 +22,12 @@ class ServerException(Exception): pass -class ExceptionUnmarshaller(xmlrpc_client.Unmarshaller): +class ExceptionUnmarshaller(xmlrpc.client.Unmarshaller): def close(self): try: - return xmlrpc_client.Unmarshaller.close(self) - except xmlrpc_client.Fault as e: + return xmlrpc.client.Unmarshaller.close(self) + except xmlrpc.client.Fault as e: raise ServerException(e.faultString) ## @@ -43,10 +38,10 @@ class ExceptionUnmarshaller(xmlrpc_client.Unmarshaller): # targetting only python-2.7 we can get rid of some older code -class XMLRPCTransport(xmlrpc_client.Transport): +class XMLRPCTransport(xmlrpc.client.Transport): def __init__(self, key_file=None, cert_file=None, timeout=None): - xmlrpc_client.Transport.__init__(self) + xmlrpc.client.Transport.__init__(self) self.timeout = timeout self.key_file = key_file self.cert_file = cert_file @@ -55,9 +50,9 @@ class XMLRPCTransport(xmlrpc_client.Transport): # create a HTTPS connection object from a host descriptor # host may be a string, or a (host, x509-dict) tuple host, extra_headers, x509 = self.get_host_info(host) - conn = http_client.HTTPSConnection(host, None, key_file=self.key_file, - cert_file=self.cert_file, - **turn_off_server_verify) + conn = http.client.HTTPSConnection( + host, None, key_file=self.key_file, + cert_file=self.cert_file, context=simple_ssl_context()) # Some logic to deal with timeouts. It appears that some (or all) versions # of python don't set the timeout after the socket is created. We'll do it @@ -80,23 +75,23 @@ class XMLRPCTransport(xmlrpc_client.Transport): def getparser(self): unmarshaller = ExceptionUnmarshaller() - parser = xmlrpc_client.ExpatParser(unmarshaller) + parser = xmlrpc.client.ExpatParser(unmarshaller) return parser, unmarshaller -class XMLRPCServerProxy(xmlrpc_client.ServerProxy): +class XMLRPCServerProxy(xmlrpc.client.ServerProxy): def __init__(self, url, transport, allow_none=True, verbose=False): # remember url for GetVersion # xxx not sure this is still needed as SfaServerProxy has this too self.url = url - xmlrpc_client.ServerProxy.__init__(self, url, transport, allow_none=allow_none, - verbose=verbose, - **turn_off_server_verify) + xmlrpc.client.ServerProxy.__init__( + self, url, transport, allow_none=allow_none, + context=simple_ssl_context(), verbose=verbose) def __getattr__(self, attr): logger.debug("xml-rpc %s method:%s" % (self.url, attr)) - return xmlrpc_client.ServerProxy.__getattr__(self, attr) + return xmlrpc.client.ServerProxy.__getattr__(self, attr) # the object on which we can send methods that get sent over xmlrpc @@ -109,7 +104,7 @@ class SfaServerProxy: self.certfile = certfile self.verbose = verbose self.timeout = timeout - # an instance of xmlrpc_client.ServerProxy + # an instance of xmlrpc.client.ServerProxy transport = XMLRPCTransport(keyfile, certfile, timeout) self.serverproxy = XMLRPCServerProxy( url, transport, allow_none=True, verbose=verbose)