当前位置: 首页>>代码示例>>Python>>正文


Python pycurl.READFUNCTION属性代码示例

本文整理汇总了Python中pycurl.READFUNCTION属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.READFUNCTION属性的具体用法?Python pycurl.READFUNCTION怎么用?Python pycurl.READFUNCTION使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在pycurl的用法示例。


在下文中一共展示了pycurl.READFUNCTION属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_raw_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import READFUNCTION [as 别名]
def get_raw_poster(self):
        """Initialze a Curl object for a single POST request.

        This sends whatever data you give it, without specifying the content
        type.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        ld = len(self._data)
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.POST, 1)
        c.setopt(c.READFUNCTION, DataWrapper(self._data).read)
        c.setopt(c.POSTFIELDSIZE, ld)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        headers = self._headers[:]
        headers.append(httputils.ContentType("")) # removes libcurl internal header
        headers.append(httputils.ContentLength(str(ld)))
        c.setopt(c.HTTPHEADER, map(str, headers))
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:25,代码来源:client.py

示例2: get_uploader

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import READFUNCTION [as 别名]
def get_uploader(self):
        """Initialze a Curl object for a single PUT request.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(pycurl.UPLOAD, 1) # does an HTTP PUT
        data = self._data.get("PUT", "")
        filesize = len(data)
        c.setopt(pycurl.READFUNCTION, DataWrapper(data).read)
        c.setopt(pycurl.INFILESIZE, filesize)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        # extra options to avoid hanging forever
        c.setopt(c.URL, str(self._url))
        c.setopt(c.HTTPHEADER, map(str, self._headers))
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:21,代码来源:client.py

示例3: test_post_data

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import READFUNCTION [as 别名]
def test_post_data(self):
        curl = CurlStub(b"result")
        result = fetch("http://example.com", post=True, data="data", curl=curl)
        self.assertEqual(result, b"result")
        self.assertEqual(curl.options[pycurl.READFUNCTION](), b"data")
        self.assertEqual(curl.options,
                         {pycurl.URL: b"http://example.com",
                          pycurl.FOLLOWLOCATION: 1,
                          pycurl.MAXREDIRS: 5,
                          pycurl.CONNECTTIMEOUT: 30,
                          pycurl.LOW_SPEED_LIMIT: 1,
                          pycurl.LOW_SPEED_TIME: 600,
                          pycurl.NOSIGNAL: 1,
                          pycurl.WRITEFUNCTION: Any(),
                          pycurl.POST: True,
                          pycurl.POSTFIELDSIZE: 4,
                          pycurl.READFUNCTION: Any(),
                          pycurl.DNS_CACHE_TIMEOUT: 0,
                          pycurl.ENCODING: b"gzip,deflate"}) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:21,代码来源:test_fetch.py

示例4: set_binary_data

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import READFUNCTION [as 别名]
def set_binary_data(self):
        """
        Set binary data to be transmitted attached to POST request.

        `binary_data` is either a bytes string, or a filename, or
        a list of key-value pairs of a multipart form.
        """

        if self.binary_data:

            if type(self.binary_data) is list:
                self.construct_binary_data()
            if type(self.binary_data) is bytes:
                self.binary_data_size = len(self.binary_data)
                self.binary_data_file = BytesIO()
                self.binary_data_file.write(self.binary_data)
                self.binary_data_file.seek(0)
            elif os.path.exists(self.binary_data):
                self.binary_data_size = os.path.getsize(self.binary_data)
                self.binary_data_file = open(self.binary_data, 'rb')

            self.curl.setopt(pycurl.POST, 1)
            self.curl.setopt(pycurl.POSTFIELDSIZE, self.binary_data_size)
            self.curl.setopt(pycurl.READFUNCTION, self.binary_data_file.read)
            self.curl.setopt(pycurl.CUSTOMREQUEST, 'POST')
            self.curl.setopt(pycurl.POSTREDIR, 3)
            self._log('Binary data added to query (not showing).') 
开发者ID:saezlab,项目名称:pypath,代码行数:29,代码来源:curl.py

示例5: request

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import READFUNCTION [as 别名]
def request(self, url, method, body, headers):
            c = pycurl.Curl()
            c.setopt(pycurl.URL, str(url))
            if 'proxy_host' in self.proxy:
                c.setopt(pycurl.PROXY, self.proxy['proxy_host'])
            if 'proxy_port' in self.proxy:
                c.setopt(pycurl.PROXYPORT, self.proxy['proxy_port'])
            if 'proxy_user' in self.proxy:
                c.setopt(pycurl.PROXYUSERPWD, "%(proxy_user)s:%(proxy_pass)s" % self.proxy)
            self.buf = StringIO()
            c.setopt(pycurl.WRITEFUNCTION, self.buf.write)
            #c.setopt(pycurl.READFUNCTION, self.read)
            #self.body = StringIO(body)
            #c.setopt(pycurl.HEADERFUNCTION, self.header)
            if self.cacert:
                c.setopt(c.CAINFO, str(self.cacert)) 
            c.setopt(pycurl.SSL_VERIFYPEER, self.cacert and 1 or 0)
            c.setopt(pycurl.SSL_VERIFYHOST, self.cacert and 2 or 0)
            c.setopt(pycurl.CONNECTTIMEOUT, self.timeout/6) 
            c.setopt(pycurl.TIMEOUT, self.timeout)
            if method=='POST':
                c.setopt(pycurl.POST, 1)
                c.setopt(pycurl.POSTFIELDS, body)            
            if headers:
                hdrs = ['%s: %s' % (str(k), str(v)) for k, v in headers.items()]
                ##print hdrs
                c.setopt(pycurl.HTTPHEADER, hdrs)
            c.perform()
            ##print "pycurl perform..."
            c.close()
            return {}, self.buf.getvalue() 
开发者ID:uwdata,项目名称:termite-visualizations,代码行数:33,代码来源:transport.py


注:本文中的pycurl.READFUNCTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。