本文整理匯總了Python中pycurl.POSTFIELDSIZE屬性的典型用法代碼示例。如果您正苦於以下問題:Python pycurl.POSTFIELDSIZE屬性的具體用法?Python pycurl.POSTFIELDSIZE怎麽用?Python pycurl.POSTFIELDSIZE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類pycurl
的用法示例。
在下文中一共展示了pycurl.POSTFIELDSIZE屬性的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_post_data
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import POSTFIELDSIZE [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"})
示例2: set_binary_data
# 需要導入模塊: import pycurl [as 別名]
# 或者: from pycurl import POSTFIELDSIZE [as 別名]
def set_binary_data(self):
"""
Set binary data to be transmitted attached to POST request.
`binary_data` is either a bytes string, or a filename, or
a list of key-value pairs of a multipart form.
"""
if self.binary_data:
if type(self.binary_data) is list:
self.construct_binary_data()
if type(self.binary_data) is bytes:
self.binary_data_size = len(self.binary_data)
self.binary_data_file = BytesIO()
self.binary_data_file.write(self.binary_data)
self.binary_data_file.seek(0)
elif os.path.exists(self.binary_data):
self.binary_data_size = os.path.getsize(self.binary_data)
self.binary_data_file = open(self.binary_data, 'rb')
self.curl.setopt(pycurl.POST, 1)
self.curl.setopt(pycurl.POSTFIELDSIZE, self.binary_data_size)
self.curl.setopt(pycurl.READFUNCTION, self.binary_data_file.read)
self.curl.setopt(pycurl.CUSTOMREQUEST, 'POST')
self.curl.setopt(pycurl.POSTREDIR, 3)
self._log('Binary data added to query (not showing).')