本文整理汇总了Python中pycurl.INFILESIZE属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.INFILESIZE属性的具体用法?Python pycurl.INFILESIZE怎么用?Python pycurl.INFILESIZE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.INFILESIZE属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_uploader
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import INFILESIZE [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
示例2: put
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import INFILESIZE [as 别名]
def put(url, data, encoding, headers=None):
"""Make a PUT request to the url, using data in the message body,
with the additional headers, if any"""
if headers is None:
headers = {}
reply = -1 # default, non-http response
curl = pycurl.Curl()
curl.setopt(pycurl.URL, url)
if len(headers) > 0:
curl.setopt(pycurl.HTTPHEADER, [k + ': ' + v for k, v in list(headers.items())])
curl.setopt(pycurl.PUT, 1)
curl.setopt(pycurl.INFILESIZE, len(data))
databuffer = BytesIO(data.encode(encoding))
curl.setopt(pycurl.READDATA, databuffer)
try:
curl.perform()
reply = curl.getinfo(pycurl.HTTP_CODE)
except Exception:
pass
curl.close()
return reply