X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=safexmlrpc.py;h=71bf4d62d478d17516d177f3952328cb785c4abd;hb=24f4b417fd6812f02ab0e88a43bce430b3913baa;hp=71799ff2e2169e4e72d9bee610e078c73a05102d;hpb=347202d6aab0acc9126767ceaf89df28a29a82ad;p=nodemanager.git diff --git a/safexmlrpc.py b/safexmlrpc.py index 71799ff..71bf4d6 100644 --- a/safexmlrpc.py +++ b/safexmlrpc.py @@ -1,27 +1,29 @@ """Leverage curl to make XMLRPC requests that check the server's credentials.""" +import xmlrpc.client + import curlwrapper -import xmlrpclib -class CertificateCheckingSafeTransport(xmlrpclib.Transport): +class CertificateCheckingSafeTransport (xmlrpc.client.Transport): + def __init__(self, cacert, timeout): self.cacert = cacert self.timeout = timeout def request(self, host, handler, request_body, verbose=0): self.verbose = verbose - try: - contents = curlwrapper.retrieve('https://%s%s' % (host, handler), - cacert = self.cacert, - postdata = request_body, - timeout = self.timeout) - return xmlrpclib.loads(contents)[0] - except curlwrapper.CurlException, e: - raise xmlrpclib.ProtocolError(host + handler, -1, str(e), '') - -class ServerProxy(xmlrpclib.ServerProxy): + url='https://%s%s' % (host, handler) + # this might raise an xmlrpclib.Protocolerror exception + contents = curlwrapper.retrieve(url, + cacert = self.cacert, + postdata = request_body, + timeout = self.timeout) + return xmlrpc.client.loads(contents)[0] + +class ServerProxy(xmlrpc.client.ServerProxy): + def __init__(self, uri, cacert, timeout = 300, **kwds): - xmlrpclib.ServerProxy.__init__(self, uri, + xmlrpc.client.ServerProxy.__init__(self, uri, CertificateCheckingSafeTransport(cacert, timeout), **kwds)