-
Notifications
You must be signed in to change notification settings - Fork 1
/
safexmlrpc.py
29 lines (21 loc) · 1.04 KB
/
safexmlrpc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Leverage curl to make XMLRPC requests that check the server's credentials."""
import xmlrpclib
import curlwrapper
class CertificateCheckingSafeTransport (xmlrpclib.Transport):
def __init__(self, cacert, timeout):
self.cacert = cacert
self.timeout = timeout
def request(self, host, handler, request_body, verbose=0):
self.verbose = verbose
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 xmlrpclib.loads(contents)[0]
class ServerProxy(xmlrpclib.ServerProxy):
def __init__(self, uri, cacert, timeout = 300, **kwds):
xmlrpclib.ServerProxy.__init__(self, uri,
CertificateCheckingSafeTransport(cacert, timeout),
**kwds)