views:

659

answers:

1

How do i turnoff WRITEFUNCTION and WRITEDATA ?

using pycurl i have a class call curlUtil. In it i have pageAsString(self, url) which returns a string. To do this i setopt WRITEFUNCTION. Now in downloadFile(self, url, fn, overwrite=0) i do an open and self.c.setopt(pycurl.WRITEFUNCTION, 0) which cause problems. int is not a valid arguement. I then assumed WRITEDATA would overwrite the value or there would be a NOWRITEFUNCTION commend. NOWRITEFUNCTION didnt exist so i just used WRITEDATA and python crashed. I wrote a quick func called reboot() which closes curl, opens it again and calls reset to put it in the default state. i call it in both pageAsString and downloadFile and there is no problem at all. But, i dont want to reinitialize curl. There might be some special options i set. How do i turnoff WRITEFUNCTION and WRITEDATA ?

-edit- a day later and i still have no idea how to solve this with something other then my current destory/create hack

+1  A: 

using the writefunction, instead of turning it off would save you a lot off trouble. you might want to rewrite your pageAsString by utilizing WRITEFUNCTION..

as an example:

from cStringIO import StringIO
c = pycurl.Curl()
buffer = StringIO()
c.setopt(pycurl.WRITEFUNCTION, buffer.write)
c.setopt(pycurl.URL, "http://example.com")
c.perform()
...
buffer.getvalue() # will return the data fetched.
hinoglu
My pageAsString works in a similar way.The problem is when i open a file in do setpot(pycurl.WRITEDATA, file). However i could change it so it would use writedata but i wanted to know how to turn it off in casei need to turn off another option.
acidzombie24
setting the writefunction to 0 will turn it off. you will have to take care of other things that libcurl will apply in that case. all are detailed here: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html
hinoglu
i do this in my C version. In pycurl i get an error :(. It doesnt allow int's as a parameter. But its fine i can fix this by using writefunction instead of writedata
acidzombie24