當前位置: 首頁>>代碼示例>>Python>>正文


Python pycurl.INFILESIZE屬性代碼示例

本文整理匯總了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 
開發者ID:kdart,項目名稱:pycopia,代碼行數:21,代碼來源:client.py

示例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 
開發者ID:dpapathanasiou,項目名稱:recipebook,代碼行數:26,代碼來源:restClient.py


注:本文中的pycurl.INFILESIZE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。