From 347202d6aab0acc9126767ceaf89df28a29a82ad Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Sat, 18 Nov 2006 18:14:55 +0000 Subject: [PATCH 1/1] support cacert specification and curl timeout --- curlwrapper.py | 6 ++++-- safexmlrpc.py | 19 ++++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/curlwrapper.py b/curlwrapper.py index ce273a3..97a35a3 100644 --- a/curlwrapper.py +++ b/curlwrapper.py @@ -3,9 +3,11 @@ from subprocess import PIPE, Popen class CurlException(Exception): pass -def retrieve(url, postdata=None): - options = ('/usr/bin/curl', '--cacert', '/usr/boot/cacert.pem') +def retrieve(url, cacert=None, postdata=None, timeout=300): + options = ('/usr/bin/curl',) + if cacert: options += ('--cacert', cacert) if postdata: options += ('--data', '@-') + if timeout: options += ('--max-time', str(timeout)) p = Popen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE) if postdata: p.stdin.write(postdata) p.stdin.close() diff --git a/safexmlrpc.py b/safexmlrpc.py index f4bd5af..71799ff 100644 --- a/safexmlrpc.py +++ b/safexmlrpc.py @@ -4,15 +4,24 @@ import curlwrapper import xmlrpclib -CURL = '/usr/bin/curl' - 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 try: - contents = curlwrapper.retrieve('https://%s%s' % (host, handler), request_body) + 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), '') + except curlwrapper.CurlException, e: + raise xmlrpclib.ProtocolError(host + handler, -1, str(e), '') class ServerProxy(xmlrpclib.ServerProxy): - def __init__(self, handler, *args, **kw_args): xmlrpclib.ServerProxy.__init__(self, handler, CertificateCheckingSafeTransport()) + def __init__(self, uri, cacert, timeout = 300, **kwds): + xmlrpclib.ServerProxy.__init__(self, uri, + CertificateCheckingSafeTransport(cacert, timeout), + **kwds) -- 2.43.0