本文整理匯總了Python中pycurl.HEADERFUNCTION屬性的典型用法代碼示例。如果您正苦於以下問題:Python pycurl.HEADERFUNCTION屬性的具體用法?Python pycurl.HEADERFUNCTION怎麽用?Python pycurl.HEADERFUNCTION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pycurl
的用法示例。
在下文中一共展示了pycurl.HEADERFUNCTION屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def request(self, method, url, body=None):
def makeRequest(ignored):
curl = CurlRequestDriver.curl
curl.reset()
curl.setopt(pycurl.URL, url)
curl.setopt(pycurl.HEADERFUNCTION, self.receiveHeaders)
curl.setopt(pycurl.WRITEFUNCTION, self.buffer.write)
curl.setopt(pycurl.CUSTOMREQUEST, method)
if body is not None:
curl.setopt(pycurl.POSTFIELDS, body)
headers = []
for key, value in six.iteritems(self.headers):
headers.append("{}: {}".format(key, value))
curl.setopt(pycurl.HTTPHEADER, headers)
d = threads.deferToThread(curl.perform)
d.addCallback(self.receive)
return d
def releaseLock(result):
CurlRequestDriver.lock.release()
# Forward the result to the next handler.
return result
d = CurlRequestDriver.lock.acquire()
# Make the request once we acquire the semaphore.
d.addCallback(makeRequest)
# Release the semaphore regardless of how the request goes.
d.addBoth(releaseLock)
return d
示例2: url_check
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def url_check(self, url):
'''下載地址檢查'''
url_info = {}
proto = urlparse.urlparse(url)[0]
if proto not in VALIDPROTOCOL:
print 'Valid protocol should be http or ftp, but % s found < %s >!' % (proto, url)
else:
ss = StringIO()
curl = pycurl.Curl()
curl.setopt(pycurl.FOLLOWLOCATION, 1)
curl.setopt(pycurl.MAXREDIRS, 5)
curl.setopt(pycurl.CONNECTTIMEOUT, 30)
curl.setopt(pycurl.TIMEOUT, 300)
curl.setopt(pycurl.NOSIGNAL, 1)
curl.setopt(pycurl.NOPROGRESS, 1)
curl.setopt(pycurl.NOBODY, 1)
curl.setopt(pycurl.HEADERFUNCTION, ss.write)
curl.setopt(pycurl.URL, url)
try:
curl.perform()
except:
pass
if curl.errstr() == '' and curl.getinfo(pycurl.RESPONSE_CODE) in STATUS_OK:
url_info['url'] = curl.getinfo(pycurl.EFFECTIVE_URL)
url_info['file'] = os.path.split(url_info['url'])[1]
url_info['size'] = int(
curl.getinfo(pycurl.CONTENT_LENGTH_DOWNLOAD))
url_info['partible'] = (ss.getvalue().find('Accept - Ranges') != -1)
return url_info
示例3: _prepare_curl_h
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def _prepare_curl_h(self, curl_h, fuzzres, poolid):
new_curl_h = fuzzres.history.to_http_object(curl_h)
new_curl_h = self._set_extra_options(new_curl_h, fuzzres, poolid)
new_curl_h.response_queue = ((BytesIO(), BytesIO(), fuzzres, poolid))
new_curl_h.setopt(pycurl.WRITEFUNCTION, new_curl_h.response_queue[0].write)
new_curl_h.setopt(pycurl.HEADERFUNCTION, new_curl_h.response_queue[1].write)
return new_curl_h
示例4: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def request(self, url, method, body, headers):
c = pycurl.Curl()
c.setopt(pycurl.URL, str(url))
if 'proxy_host' in self.proxy:
c.setopt(pycurl.PROXY, self.proxy['proxy_host'])
if 'proxy_port' in self.proxy:
c.setopt(pycurl.PROXYPORT, self.proxy['proxy_port'])
if 'proxy_user' in self.proxy:
c.setopt(pycurl.PROXYUSERPWD, "%(proxy_user)s:%(proxy_pass)s" % self.proxy)
self.buf = StringIO()
c.setopt(pycurl.WRITEFUNCTION, self.buf.write)
#c.setopt(pycurl.READFUNCTION, self.read)
#self.body = StringIO(body)
#c.setopt(pycurl.HEADERFUNCTION, self.header)
if self.cacert:
c.setopt(c.CAINFO, str(self.cacert))
c.setopt(pycurl.SSL_VERIFYPEER, self.cacert and 1 or 0)
c.setopt(pycurl.SSL_VERIFYHOST, self.cacert and 2 or 0)
c.setopt(pycurl.CONNECTTIMEOUT, self.timeout/6)
c.setopt(pycurl.TIMEOUT, self.timeout)
if method=='POST':
c.setopt(pycurl.POST, 1)
c.setopt(pycurl.POSTFIELDS, body)
if headers:
hdrs = ['%s: %s' % (str(k), str(v)) for k, v in headers.items()]
##print hdrs
c.setopt(pycurl.HTTPHEADER, hdrs)
c.perform()
##print "pycurl perform..."
c.close()
return {}, self.buf.getvalue()
示例5: __init__
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def __init__(self, base_url="", fakeheaders=[]):
self.handle = pycurl.Curl()
# These members might be set.
self.set_url(base_url)
self.verbosity = 0
self.fakeheaders = fakeheaders
# Nothing past here should be modified by the caller.
self.payload = None
self.payload_io = BytesIO()
self.hrd = ""
# Verify that we've got the right site; harmless on a non-SSL connect.
self.set_option(pycurl.SSL_VERIFYHOST, 2)
# Follow redirects in case it wants to take us to a CGI...
self.set_option(pycurl.FOLLOWLOCATION, 1)
self.set_option(pycurl.MAXREDIRS, 5)
self.set_option(pycurl.NOSIGNAL, 1)
# Setting this option with even a nonexistent file makes libcurl
# handle cookie capture and playback automatically.
self.set_option(pycurl.COOKIEFILE, "/dev/null")
# Set timeouts to avoid hanging too long
self.set_timeout(30)
# Use password identification from .netrc automatically
self.set_option(pycurl.NETRC, 1)
self.set_option(pycurl.WRITEFUNCTION, self.payload_io.write)
def header_callback(x):
self.hdr += x.decode('ascii')
self.set_option(pycurl.HEADERFUNCTION, header_callback)
示例6: _set_only_receive_headers
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def _set_only_receive_headers(self):
self._curl.setopt(pycurl.VERBOSE, True)
self._curl.setopt(pycurl.RANGE, "0-0")
self._curl.setopt(pycurl.HEADERFUNCTION, self._response_header_handler.response_header_handler)
self._curl.setopt(pycurl.WRITEDATA, None)
示例7: perform
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def perform(self):
self.__performHead=""
self.__performBody=""
conn=pycurl.Curl()
conn.setopt(pycurl.SSL_VERIFYPEER,False)
conn.setopt(pycurl.SSL_VERIFYHOST,1)
conn.setopt(pycurl.URL,self.completeUrl)
if self.__method or self.__userpass:
if self.__method=="basic":
conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_BASIC)
elif self.__method=="ntlm":
conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_NTLM)
elif self.__method=="digest":
conn.setopt(pycurl.HTTPAUTH, pycurl.HTTPAUTH_DIGEST)
conn.setopt(pycurl.USERPWD, self.__userpass)
if self.__timeout:
conn.setopt(pycurl.CONNECTTIMEOUT, self.__timeout)
conn.setopt(pycurl.NOSIGNAL, 1)
if self.__totaltimeout:
conn.setopt(pycurl.TIMEOUT, self.__totaltimeout)
conn.setopt(pycurl.NOSIGNAL, 1)
conn.setopt(pycurl.WRITEFUNCTION, self.body_callback)
conn.setopt(pycurl.HEADERFUNCTION, self.header_callback)
if self.__proxy!=None:
conn.setopt(pycurl.PROXY,self.__proxy)
if self.__headers.has_key("Proxy-Connection"):
del self.__headers["Proxy-Connection"]
conn.setopt(pycurl.HTTPHEADER,self.__getHeaders())
if self.method=="POST":
conn.setopt(pycurl.POSTFIELDS,self.__postdata)
conn.perform()
rp=Response()
rp.parseResponse(self.__performHead)
rp.addContent(self.__performBody)
self.response=rp
######### ESTE conjunto de funciones no es necesario para el uso habitual de la clase
示例8: request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import HEADERFUNCTION [as 別名]
def request(self, path="/", header=None, ssl=False, timeout=None):
if timeout is None:
timeout = self.timeout
buf = StringIO()
c = pycurl.Curl()
if header:
slist = []
for key, value in header.iteritems():
slist.append(key+": "+value)
c.setopt(pycurl.HTTPHEADER, slist)
c.setopt(pycurl.HEADERFUNCTION, self.header_function)
c.setopt(pycurl.FOLLOWLOCATION, True)
c.setopt(pycurl.WRITEDATA, buf)
c.setopt(pycurl.TIMEOUT, timeout)
c.setopt(pycurl.ENCODING, 'identity')
c.setopt(pycurl.NOSIGNAL, 1)
if ssl:
if self.port is None:
self.port = 443
c.setopt(pycurl.URL, "https://"+self.host+":"+str(self.port)+path)
c.setopt(pycurl.SSL_VERIFYPEER, 1)
c.setopt(pycurl.SSL_VERIFYHOST, 2)
else:
if self.port is None:
self.port = 80
c.setopt(pycurl.URL,"http://"+self.host + ":" + str(self.port) + path)
c.perform()
self.status = c.getinfo(pycurl.RESPONSE_CODE)
c.close()
encoding = None
if 'content-type' in self.headers:
content_type = self.headers['content-type'].lower()
match = re.search('charset=(\S+)', content_type)
if match:
encoding = match.group(1)
if encoding is None:
# Default encoding for HTML is iso-8859-1.
# Other content types may have different default encoding,
# or in case of binary data, may have no encoding at all.
encoding = 'iso-8859-1'
self.body = buf.getvalue().decode(encoding)