1 from subprocess import PIPE, Popen
4 class CurlException(Exception): pass
6 def retrieve(url, cacert=None, postdata=None, timeout=300):
7 options = ('/usr/bin/curl', '--fail', '--silent')
8 if cacert: options += ('--cacert', cacert)
9 if postdata: options += ('--data', '@-')
10 if timeout: options += ('--max-time', str(timeout))
11 p = Popen(options + (url,), stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
12 if postdata: p.stdin.write(postdata)
14 data = p.stdout.read()
17 if rc != 0: raise CurlException(err)