def _clear(self): self._buff.clear() for k in self._slist: lib.curl_slist_free_all(self._slist[k]) self._slist.clear()
def setopt(name, value): option_name = 'CURLOPT_%s' % name.upper() if name.islower() and hasattr(const, option_name): option_value = getattr(const, option_name) if name in self._CURLOPT_SLIST: value = lib.list2pointer_slist(value) if name in self._slist: lib.curl_slist_free_all(self._slist[name]) del self._slist[name] else: self._slist[name] = value elif hasattr(prototype, name): if callable(value): value = getattr(prototype, name)(value) elif name == 'postfields' and isinstance(value, dict): value = urllib.urlencode(value) elif name == 'share': value = value._handle elif name == 'url' and value: value = iri2uri(value) if isinstance(value, unicode): value = value.encode('utf-8') # setopt lib.curl_easy_setopt(self._handle, option_value, value) #print option_name, value self._buff[option_name] = value else: raise ValueError('invalid option name "%s"' % name)