from sfa.util.sfalogging import logger
except:
import logging
- logger=logging.getLogger('sfaserverproxy')
+ logger = logging.getLogger('sfaserverproxy')
##
# ServerException, ExceptionUnmarshaller
#
# A transport for XMLRPC that works on top of HTTPS
-# python 2.7 xmlrpclib has changed its internal code
-# it now calls 'getresponse' on the obj returned by make_connection
-# while it used to call 'getreply'
-# regardless of the version, httplib.HTTPS does implement getreply,
-# while httplib.HTTPSConnection has getresponse
-# so we create a dummy instance to check what's expected
-need_HTTPSConnection=hasattr(xmlrpclib.Transport().make_connection('localhost'),'getresponse')
+# targetting only python-2.7 we can get rid of some older code
class XMLRPCTransport(xmlrpclib.Transport):
- def __init__(self, key_file=None, cert_file=None, timeout=None):
+ def __init__(self, key_file = None, cert_file = None, timeout = None):
xmlrpclib.Transport.__init__(self)
self.timeout=timeout
self.key_file = key_file
# 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)
- if need_HTTPSConnection:
- if not ssl_needs_unverified_context:
- conn = HTTPSConnection(host, None, key_file = self.key_file,
- cert_file = self.cert_file)
- else:
- conn = HTTPSConnection(host, None, key_file = self.key_file,
- cert_file = self.cert_file,
- context = ssl._create_unverified_context())
+ if not ssl_needs_unverified_context:
+ conn = HTTPSConnection(host, None, key_file = self.key_file,
+ cert_file = self.cert_file)
else:
- conn = HTTPS(host, None, key_file=self.key_file, cert_file=self.cert_file)
+ conn = HTTPSConnection(host, None, key_file = self.key_file,
+ cert_file = self.cert_file,
+ context = ssl._create_unverified_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
class SfaServerProxy:
def __init__ (self, url, keyfile, certfile, verbose=False, timeout=None):
- self.url=url
- self.keyfile=keyfile
- self.certfile=certfile
- self.verbose=verbose
- self.timeout=timeout
+ self.url = url
+ self.keyfile = keyfile
+ self.certfile = certfile
+ self.verbose = verbose
+ self.timeout = timeout
# an instance of xmlrpclib.ServerProxy
transport = XMLRPCTransport(keyfile, certfile, timeout)
self.serverproxy = XMLRPCServerProxy(url, transport, allow_none=True, verbose=verbose)