- curl.setopt(pycurl.CONNECTTIMEOUT, timeout)
- curl.setopt(pycurl.TIMEOUT, timeout)
-
- # set cacert
- if cacert:
- curl.setopt(pycurl.CAINFO, cacert)
- curl.setopt(pycurl.SSL_VERIFYPEER, 2)
- else:
- curl.setopt(pycurl.SSL_VERIFYPEER, 0)
-
- # set postdata
- if postdata:
- if isinstance(postdata,dict):
- postfields = urllib.urlencode(postdata)
- else:
- postfields=postdata
- curl.setopt(pycurl.POSTFIELDS, postfields)
-
- # go
- try:
- curl.perform()
-
- errcode = curl.getinfo(pycurl.HTTP_CODE)
- curl.close()
-
- # check the code, return 1 if successfull
- if errcode == 60:
- raise xmlrpclib.ProtocolError (url,errcode, "SSL certificate validation failed", postdata)
- elif errcode != 200:
- raise xmlrpclib.ProtocolError (url,errcode, "http error %d"%errcode, postdata)
-
- except pycurl.error, err:
- errno, errstr = err
- raise xmlrpclib.ProtocolError(url, errno, "curl error %d: '%s'\n" %(errno,errstr),postdata )
-
- return buffer.getvalue()
+ command += ('--max-time', str(timeout))
+ command += ('--connect-timeout', str(timeout))
+ command += (url,)
+ if verbose:
+ print 'Invoking ',command
+ if postdata: print 'with postdata=',postdata
+ p = Sopen(command , stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
+ if postdata: p.stdin.write(postdata)
+ p.stdin.close()
+ sout, sin, serr = select([p.stdout,p.stderr],[],[], timeout)
+ if len(sout) == 0 and len(sin) == 0 and len(serr) == 0:
+ logger.verbose("curlwrapper: timed out after %s" % timeout)
+ p.kill(signal.SIGKILL)
+ data = p.stdout.read()
+ err = p.stderr.read()
+ rc = p.wait()
+ if rc != 0:
+ # when this triggers, the error sometimes doesn't get printed
+ logger.log ("curlwrapper: retrieve, got stderr <%s>"%err)
+ raise xmlrpclib.ProtocolError(url, rc, err, postdata)
+ else:
+ return data