Python pycurl.INFILESIZE Examples

The following are 2 code examples of pycurl.INFILESIZE(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pycurl , or try the search function .
Example #1
Source File: client.py    From pycopia with Apache License 2.0 6 votes vote down vote up
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 
Example #2
Source File: restClient.py    From recipebook with MIT License 6 votes vote down vote up
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