class Browser(object):
options = {
...
}
def fetch(self, url, data=None):
def setoptDict(curlObj, optDict):
for optName, optValue in optDict.iteritems():
curlObj.setopt(getattr(pycurl, optName), optValue)
buf = StringIO()
headers = StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.URL, str(url))
curl.setopt(pycurl.WRITEFUNCTION, buf.write)
curl.setopt(pycurl.HEADERFUNCTION, headers.write)
setoptDict(curl, self.options)
curl.perform()
return buf.getvalue()
def asyncFetch(self, *args, **kwargs):
return deferToThread(self.fetch, *args, **kwargs)
Сразу признаюсь, что в twisted ничегошеньки не понимаю, документацию на английском читал, но не осилил. Помогите, люди добрые.