curl-and-python

re: help with pycurl/win32 and HTTP PUT

From: Kjetil Jacobsen <kjetilja_at_cs.uit.no>
Date: Wed, 9 Feb 2005 13:10:22 +0100 (CET)

hello,

there is some information wrt callbacks and pycurl at

        http://pycurl.sf.net/doc/callbacks.html

in particular, READDATA cannot be used when READFUNCTION is specified.
fortunately, this limitation can be overcome by using a class to store the
file reference (instead of using READDATA) and then set a class method as
the callback function like this:

class filereader:

    def __init__(self, f):
        self.f = f

    def read_callback(self, size):
        return self.f.read(size)

import pycurl
c = pycurl.Curl()
f = filereader(open('somefile'))
c.setopt(c.URL, 'http://somehere/')
c.setopt(c.READFUNCTION, f.read_callback)

...

regards,

        - kjetil

_______________________________________________
http://cool.haxx.se/mailman/listinfo/curl-and-python
Received on 2005-02-09