本文整理匯總了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