本文整理匯總了Python中pycurl.WRITEFUNCTION屬性的典型用法代碼示例。如果您正苦於以下問題:Python pycurl.WRITEFUNCTION屬性的具體用法?Python pycurl.WRITEFUNCTION怎麽用?Python pycurl.WRITEFUNCTION使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pycurl
的用法示例。
在下文中一共展示了pycurl.WRITEFUNCTION屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: query
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = StringIO.StringIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.CONNECTTIMEOUT, CONNECTION_TIMEOUT)
query.setopt(pycurl.WRITEFUNCTION, output.write)
try:
query.perform()
return output.getvalue()
except pycurl.error as exc:
raise ValueError("Unable to reach %s (%s)" % (url, exc))
示例2: query
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def query(url):
"""
Uses pycurl to fetch a site using the proxy on the SOCKS_PORT.
"""
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, url)
query.setopt(pycurl.PROXY, 'localhost')
query.setopt(pycurl.PROXYPORT, SOCKS_PORT)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.WRITEFUNCTION, output.write)
try:
query.perform()
return output.getvalue()
except pycurl.error as exc:
return "Unable to reach %s (%s)" % (url, exc)
# Start an instance of Tor configured to only exit through Russia. This prints
# Tor's bootstrap information as it starts. Note that this likely will not
# work if you have another Tor instance running.
示例3: _check_status
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def _check_status(self):
"""
For internal use only. Only members of :class:`Tunnel`
"""
try:
output = io.BytesIO()
query = pycurl.Curl()
query.setopt(pycurl.URL, "%s:%s" % (self.addr, self.status_server.port))
query.setopt(pycurl.PROXY, "127.0.0.1")
query.setopt(pycurl.PROXYPORT, config.tor_proxy_port)
query.setopt(pycurl.PROXYTYPE, pycurl.PROXYTYPE_SOCKS5_HOSTNAME)
query.setopt(pycurl.WRITEFUNCTION, output.write)
query.perform()
return "ONIONGROK_CLIENT_STATUS_SUCCESS" in output.getvalue().decode("utf8")
except Exception as e:
return False
示例4: test_post
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def test_post(self):
curl = CurlStub(b"result")
result = fetch("http://example.com", post=True, curl=curl)
self.assertEqual(result, b"result")
self.assertEqual(curl.options,
{pycurl.URL: b"http://example.com",
pycurl.FOLLOWLOCATION: 1,
pycurl.MAXREDIRS: 5,
pycurl.CONNECTTIMEOUT: 30,
pycurl.LOW_SPEED_LIMIT: 1,
pycurl.LOW_SPEED_TIME: 600,
pycurl.NOSIGNAL: 1,
pycurl.WRITEFUNCTION: Any(),
pycurl.POST: True,
pycurl.DNS_CACHE_TIMEOUT: 0,
pycurl.ENCODING: b"gzip,deflate"})
示例5: test_post_data
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def test_post_data(self):
curl = CurlStub(b"result")
result = fetch("http://example.com", post=True, data="data", curl=curl)
self.assertEqual(result, b"result")
self.assertEqual(curl.options[pycurl.READFUNCTION](), b"data")
self.assertEqual(curl.options,
{pycurl.URL: b"http://example.com",
pycurl.FOLLOWLOCATION: 1,
pycurl.MAXREDIRS: 5,
pycurl.CONNECTTIMEOUT: 30,
pycurl.LOW_SPEED_LIMIT: 1,
pycurl.LOW_SPEED_TIME: 600,
pycurl.NOSIGNAL: 1,
pycurl.WRITEFUNCTION: Any(),
pycurl.POST: True,
pycurl.POSTFIELDSIZE: 4,
pycurl.READFUNCTION: Any(),
pycurl.DNS_CACHE_TIMEOUT: 0,
pycurl.ENCODING: b"gzip,deflate"})
示例6: test_cainfo
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def test_cainfo(self):
curl = CurlStub(b"result")
result = fetch("https://example.com", cainfo="cainfo", curl=curl)
self.assertEqual(result, b"result")
self.assertEqual(curl.options,
{pycurl.URL: b"https://example.com",
pycurl.FOLLOWLOCATION: 1,
pycurl.MAXREDIRS: 5,
pycurl.CONNECTTIMEOUT: 30,
pycurl.LOW_SPEED_LIMIT: 1,
pycurl.LOW_SPEED_TIME: 600,
pycurl.NOSIGNAL: 1,
pycurl.WRITEFUNCTION: Any(),
pycurl.CAINFO: b"cainfo",
pycurl.DNS_CACHE_TIMEOUT: 0,
pycurl.ENCODING: b"gzip,deflate"})
示例7: test_timeouts
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def test_timeouts(self):
curl = CurlStub(b"result")
result = fetch("http://example.com", connect_timeout=5,
total_timeout=30, curl=curl)
self.assertEqual(result, b"result")
self.assertEqual(curl.options,
{pycurl.URL: b"http://example.com",
pycurl.FOLLOWLOCATION: 1,
pycurl.MAXREDIRS: 5,
pycurl.CONNECTTIMEOUT: 5,
pycurl.LOW_SPEED_LIMIT: 1,
pycurl.LOW_SPEED_TIME: 30,
pycurl.NOSIGNAL: 1,
pycurl.WRITEFUNCTION: Any(),
pycurl.DNS_CACHE_TIMEOUT: 0,
pycurl.ENCODING: b"gzip,deflate"})
示例8: test_pycurl_insecure
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def test_pycurl_insecure(self):
curl = CurlStub(b"result")
result = fetch("http://example.com/get-ca-cert", curl=curl,
insecure=True)
self.assertEqual(result, b"result")
self.assertEqual(curl.options,
{pycurl.URL: b"http://example.com/get-ca-cert",
pycurl.FOLLOWLOCATION: 1,
pycurl.MAXREDIRS: 5,
pycurl.CONNECTTIMEOUT: 30,
pycurl.LOW_SPEED_LIMIT: 1,
pycurl.LOW_SPEED_TIME: 600,
pycurl.NOSIGNAL: 1,
pycurl.WRITEFUNCTION: Any(),
pycurl.SSL_VERIFYPEER: False,
pycurl.DNS_CACHE_TIMEOUT: 0,
pycurl.ENCODING: b"gzip,deflate"})
示例9: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(ip, port, payload):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/server/restart" %(
ip, port)
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.POST, 1)
conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None
# end def send_REST_request
示例10: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(ip, port, object, match_key,
match_value, detail):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/%s" % (ip, port, object)
args_str = ''
if match_key:
args_str += match_key + "=" + match_value
if detail:
args_str += "&detail"
if args_str != '':
url += "?" + args_str
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.HTTPGET, 1)
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None
# end def send_REST_request
示例11: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(ip, port, payload):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/server/reimage" %(
ip, port)
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.POST, 1)
conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None
示例12: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(self, server_ip, port):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/%s" % (server_ip, port, 'MonitorInfo')
args_str = ''
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.HTTPGET, 1)
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
data_dict = response.getvalue()
data_dict = dict(json.loads(data_dict))
data_list = list(data_dict["__ServerMonitoringInfoTrace_list"]["ServerMonitoringInfoTrace"])
return data_list
except Exception as e:
print "Error is: " + str(e)
return None
# end def send_REST_request
示例13: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(ip, port, payload):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/server/provision" %(
ip, port)
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.POST, 1)
conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None
示例14: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(ip, port, object, key, value, force=False):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/%s?%s=%s" %(
ip, port, object,
urllib.quote_plus(key),
urllib.quote_plus(value))
if force:
url += "&force"
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.HTTPHEADER, headers)
conn.setopt(pycurl.CUSTOMREQUEST, "delete")
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None
# end def send_REST_request
示例15: send_REST_request
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import WRITEFUNCTION [as 別名]
def send_REST_request(ip, port, payload, file_name,
kickstart='', kickseed=''):
try:
response = StringIO()
headers = ["Content-Type:application/json"]
url = "http://%s:%s/image/upload" %(
ip, port)
conn = pycurl.Curl()
conn.setopt(pycurl.URL, url)
conn.setopt(pycurl.POST, 1)
payload["file"] = (pycurl.FORM_FILE, file_name)
if kickstart:
payload["kickstart"] = (pycurl.FORM_FILE, kickstart)
if kickseed:
payload["kickseed"] = (pycurl.FORM_FILE, kickseed)
conn.setopt(pycurl.HTTPPOST, payload.items())
conn.setopt(pycurl.CUSTOMREQUEST, "PUT")
conn.setopt(pycurl.WRITEFUNCTION, response.write)
conn.perform()
return response.getvalue()
except:
return None