get rid of curlwrapper.CurlException and raise xmlrpclib.ProtocolError instead
[nodemanager.git] / safexmlrpc.py
1 # $Id$
2
3 """Leverage curl to make XMLRPC requests that check the server's credentials."""
4
5 import curlwrapper
6
7 class CertificateCheckingSafeTransport (xmlrpclib.Transport):
8
9     def __init__(self, cacert, timeout):
10         self.cacert = cacert
11         self.timeout = timeout
12
13     def request(self, host, handler, request_body, verbose=0):
14         self.verbose = verbose
15         url='https://%s%s' % (host, handler)
16         # this might raise an xmlrpclib.Protocolerror exception
17         contents = curlwrapper.retrieve(url,
18                                         cacert = self.cacert,
19                                         postdata = request_body,
20                                         timeout = self.timeout)
21         return xmlrpclib.loads(contents)[0]
22
23 class ServerProxy(xmlrpclib.ServerProxy):
24
25     def __init__(self, uri, cacert, timeout = 300, **kwds):
26         xmlrpclib.ServerProxy.__init__(self, uri,
27                                        CertificateCheckingSafeTransport(cacert, timeout),
28                                        **kwds)