Python pycurl 模块,CONNECTTIMEOUT_MS 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用pycurl.CONNECTTIMEOUT_MS

项目:searx-stats2    作者:dalf    | 项目源码 | 文件源码
def set_timeout(self, timeout):
        self.timeout = int(timeout)
        self.curl_handler.setopt(pycurl.CONNECTTIMEOUT_MS, self.timeout)
        self.curl_handler.setopt(pycurl.TIMEOUT_MS, self.timeout)
项目:searx-stats2    作者:dalf    | 项目源码 | 文件源码
def __init__(self,
                 url,
                 curl_handler,
                 method='GET',
                 headers=None,
                 cookies=None,
                 callback=None,
                 callback_parameters=None,
                 data=None,
                 timeout=5000,
                 ssl_verification=True,
                 proxy=None
                 ):

        if headers is None:
            headers = {}

        if cookies is None:
            cookies = {}

        if callback is None:
            callback = callback_get_response

        if callback_parameters is None:
            callback_parameters = ()

        self.url = url
        self.timeout = timeout

        self.callback = callback
        self.callback_parameters = callback_parameters
        self.curl_handler = curl_handler
        self._response_buffer = BytesIO()
        self.response = None

        # curl_handler
        curl_handler.setopt(curl_handler.URL, url)

        curl_handler.setopt(curl_handler.WRITEFUNCTION, self._response_buffer.write)

        curl_handler.setopt(curl_handler.SSL_VERIFYPEER, int(ssl_verification))

        curl_handler.setopt(curl_handler.CONNECTTIMEOUT_MS, self.timeout)
        curl_handler.setopt(curl_handler.TIMEOUT_MS, self.timeout)

        curl_handler.setopt(curl_handler.HTTPHEADER,
                            ['{0}: {1}'.format(k, v)
                             for k, v in headers.items()])

        if data is not None:
            curl_handler.setopt(curl_handler.POSTFIELDS, urlencode(data))

        if proxy is not None:
            curl_handler.setopt(curl_handler.PROXY, proxy)

        if cookies:
            curl_handler.setopt(curl_handler.COOKIE, '; '.join('{0}={1}'.format(k, v)
                                for k, v in cookies.items()))
        else:
            curl_handler.unsetopt(curl_handler.COOKIE)