本文整理汇总了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).')