当前位置: 首页>>代码示例>>Python>>正文


Python urllib3.encode_multipart_formdata函数代码示例

本文整理汇总了Python中urllib3.encode_multipart_formdata函数的典型用法代码示例。如果您正苦于以下问题:Python encode_multipart_formdata函数的具体用法?Python encode_multipart_formdata怎么用?Python encode_multipart_formdata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了encode_multipart_formdata函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

def main(config, istream, job, hashtag, desc, login, passwd, report_empty=False):
    file_data = istream.read()
    # check the data
    report_tree = ET.parse(StringIO.StringIO(file_data))
    if not report_tree.getroot().getchildren() and not report_empty:
        # nothing to report and user not interested in reporting empty result
        print "nothing to report..."
        return
    params = {"parameter": [{'name':'report.xml', 'file': 'file0'},{"name": "desc", "value": hashtag}]}
    data, content_type = urllib3.encode_multipart_formdata([
        ("file0", (istream.name, file_data)),
        ("json", json.dumps(params)),
        ("Submit", "Build"),
        ])
    url = job + 'build'
    r = requests.post(url, auth=(login, passwd), data=data, headers={"content-type": content_type})
    if not r.ok:
        print "Authentification failure."
        exit(1)
    print "Waiting 10s for build to be finished."
    time.sleep(10)
    url = job + 'api/xml'
    xpath_str = "//build//*[contains(text(),'"+ hashtag +"')]/../../../url"
    params = {'depth': '1', 'xpath': xpath_str, 'wrapper': 'list'}
    r = requests.get(url, auth=(login, passwd), params=params)
    
    tree = ET.fromstring(r.text.replace('</url>','</url>\n'))
    notags = ET.tostring(tree, encoding='utf8', method='text')
    job_number = notags.splitlines()[0].rsplit('/',2)[1]

    url = job + 'default/' + job_number + '/testReport/submitDescription'
    params = {'description': desc}
    r = requests.get(url, auth=(login,passwd), params=params)

    print "Return code: " + str(r.status_code)
开发者ID:RedHatQE,项目名称:dva,代码行数:35,代码来源:jenkins.py

示例2: test_lazy_load_twice

    def test_lazy_load_twice(self):
        # This test is sad and confusing. Need to figure out what's
        # going on with partial reads and socket reuse.

        pool = HTTPConnectionPool(self.host, self.port, block=True, maxsize=1, timeout=2)

        payload_size = 1024 * 2
        first_chunk = 512

        boundary = "foo"

        req_data = {"count": "a" * payload_size}
        resp_data = encode_multipart_formdata(req_data, boundary=boundary)[0]

        req2_data = {"count": "b" * payload_size}
        resp2_data = encode_multipart_formdata(req2_data, boundary=boundary)[0]

        r1 = pool.request("POST", "/echo", fields=req_data, multipart_boundary=boundary, preload_content=False)

        self.assertEqual(r1.read(first_chunk), resp_data[:first_chunk])

        try:
            r2 = pool.request(
                "POST",
                "/echo",
                fields=req2_data,
                multipart_boundary=boundary,
                preload_content=False,
                pool_timeout=0.001,
            )

            # This branch should generally bail here, but maybe someday it will
            # work? Perhaps by some sort of magic. Consider it a TODO.

            self.assertEqual(r2.read(first_chunk), resp2_data[:first_chunk])

            self.assertEqual(r1.read(), resp_data[first_chunk:])
            self.assertEqual(r2.read(), resp2_data[first_chunk:])
            self.assertEqual(pool.num_requests, 2)

        except EmptyPoolError:
            self.assertEqual(r1.read(), resp_data[first_chunk:])
            self.assertEqual(pool.num_requests, 1)

        self.assertEqual(pool.num_connections, 1)
开发者ID:aliyun,项目名称:aliyun-tablestore-tutorials,代码行数:45,代码来源:test_connectionpool.py

示例3: test_post_with_multipart

    def test_post_with_multipart(self):
        data = {"banana": "hammock", "lol": "cat"}
        r = self.pool.request("POST", "/echo", fields=data, encode_multipart=True)
        body = r.data.split(b"\r\n")

        encoded_data = encode_multipart_formdata(data)[0]
        expected_body = encoded_data.split(b"\r\n")

        # TODO: Get rid of extra parsing stuff when you can specify
        # a custom boundary to encode_multipart_formdata
        """
        We need to loop the return lines because a timestamp is attached
        from within encode_multipart_formdata. When the server echos back
        the data, it has the timestamp from when the data was encoded, which
        is not equivalent to when we run encode_multipart_formdata on
        the data again.
        """
        for i, line in enumerate(body):
            if line.startswith(b"--"):
                continue

            self.assertEqual(body[i], expected_body[i])
开发者ID:aliyun,项目名称:aliyun-tablestore-tutorials,代码行数:22,代码来源:test_connectionpool.py


注:本文中的urllib3.encode_multipart_formdata函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。