本文整理汇总了Python中pycurl.UPLOAD属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.UPLOAD属性的具体用法?Python pycurl.UPLOAD怎么用?Python pycurl.UPLOAD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pycurl
的用法示例。
在下文中一共展示了pycurl.UPLOAD属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_uploader
# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import UPLOAD [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