X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Fclient%2Fsfaserverproxy.py;h=73aefc8c6d29c8b34afd0f8712ea25b566072017;hb=eabad1f49b519d0a7b73a2644c14a94e87545dda;hp=333984c67779a90f1e0b7aedca3a1e6293d2f54f;hpb=06768bd605e5d47fadfc90a35c74e30f267226a5;p=sfa.git diff --git a/sfa/client/sfaserverproxy.py b/sfa/client/sfaserverproxy.py index 333984c6..73aefc8c 100644 --- a/sfa/client/sfaserverproxy.py +++ b/sfa/client/sfaserverproxy.py @@ -2,12 +2,13 @@ # 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 httplib import HTTPS, HTTPSConnection +try: + turn_off_server_verify = {'context': ssl._create_unverified_context()} +except: + turn_off_server_verify = {} from sfa.util.py23 import xmlrpc_client +from sfa.util.py23 import http_client try: from sfa.util.sfalogging import logger @@ -21,10 +22,13 @@ except: # Used to convert server exception strings back to an exception. # from usenet, Raghuram Devarakonda + class ServerException(Exception): pass + class ExceptionUnmarshaller(xmlrpc_client.Unmarshaller): + def close(self): try: return xmlrpc_client.Unmarshaller.close(self) @@ -38,21 +42,22 @@ class ExceptionUnmarshaller(xmlrpc_client.Unmarshaller): # targetting only python-2.7 we can get rid of some older code + class XMLRPCTransport(xmlrpc_client.Transport): - - def __init__(self, key_file = None, cert_file = None, timeout = None): + + def __init__(self, key_file=None, cert_file=None, timeout=None): xmlrpc_client.Transport.__init__(self) - self.timeout=timeout + self.timeout = timeout self.key_file = key_file self.cert_file = cert_file - + 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 host, extra_headers, x509 = self.get_host_info(host) - conn = 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, + **turn_off_server_verify) # 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 @@ -78,23 +83,27 @@ class XMLRPCTransport(xmlrpc_client.Transport): parser = xmlrpc_client.ExpatParser(unmarshaller) return parser, unmarshaller + 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) + **turn_off_server_verify) def __getattr__(self, attr): - logger.debug ("xml-rpc %s method:%s" % (self.url, attr)) + logger.debug("xml-rpc %s method:%s" % (self.url, attr)) return xmlrpc_client.ServerProxy.__getattr__(self, attr) -########## the object on which we can send methods that get sent over xmlrpc +# the object on which we can send methods that get sent over xmlrpc + + class SfaServerProxy: - def __init__ (self, url, keyfile, certfile, verbose=False, timeout=None): + def __init__(self, url, keyfile, certfile, verbose=False, timeout=None): self.url = url self.keyfile = keyfile self.certfile = certfile @@ -102,9 +111,10 @@ class SfaServerProxy: self.timeout = timeout # an instance of xmlrpc_client.ServerProxy transport = XMLRPCTransport(keyfile, certfile, timeout) - self.serverproxy = XMLRPCServerProxy(url, transport, allow_none=True, verbose=verbose) + self.serverproxy = XMLRPCServerProxy( + url, transport, allow_none=True, verbose=verbose) - # this is python magic to return the code to run when + # this is python magic to return the code to run when # SfaServerProxy receives a method call # so essentially we send the same method with identical arguments # to the server_proxy object @@ -112,4 +122,3 @@ class SfaServerProxy: def func(*args, **kwds): return getattr(self.serverproxy, name)(*args, **kwds) return func -