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


Python six.b函数代码示例

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


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

示例1: test_field_encoding

    def test_field_encoding(self):
        fieldsets = [
            [('k', 'v'), ('k2', 'v2')],
            [('k', b'v'), (u('k2'), b'v2')],
            [('k', b'v'), (u('k2'), 'v2')],
        ]

        for fields in fieldsets:
            encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)

            self.assertEqual(encoded,
                b'--' + b(BOUNDARY) + b'\r\n'
                b'Content-Disposition: form-data; name="k"\r\n'
                b'Content-Type: text/plain\r\n'
                b'\r\n'
                b'v\r\n'
                b'--' + b(BOUNDARY) + b'\r\n'
                b'Content-Disposition: form-data; name="k2"\r\n'
                b'Content-Type: text/plain\r\n'
                b'\r\n'
                b'v2\r\n'
                b'--' + b(BOUNDARY) + b'--\r\n'
                , fields)

            self.assertEqual(content_type,
                b'multipart/form-data; boundary=' + b(BOUNDARY))
开发者ID:DazWorrall,项目名称:urllib3,代码行数:26,代码来源:test_filepost.py

示例2: test_filename

    def test_filename(self):
        fields = [('k', ('somename', b'v'))]

        encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)

        self.assertEqual(encoded,
            b'--' + b(BOUNDARY) + b'\r\n'
            b'Content-Disposition: form-data; name="k"; filename="somename"\r\n'
            b'Content-Type: application/octet-stream\r\n'
            b'\r\n'
            b'v\r\n'
            b'--' + b(BOUNDARY) + b'--\r\n'
            )

        self.assertEqual(content_type,
            b'multipart/form-data; boundary=' + b(BOUNDARY))


	def test_textplain(self):
	    fields = [('k', ('somefile.txt', b'v'))]

	    encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)

	    self.assertEqual(encoded,
	        b'--' + b(BOUNDARY) + b'\r\n'
	        b'Content-Disposition: form-data; name="k"; filename="somefile.txt"\r\n'
	        b'Content-Type: text/plain\r\n'
	        b'\r\n'
	        b'v\r\n'
	        b'--' + b(BOUNDARY) + b'--\r\n'
	        )

	    self.assertEqual(content_type,
	        b'multipart/form-data; boundary=' + b(BOUNDARY))
开发者ID:Bluehorn,项目名称:urllib3,代码行数:34,代码来源:test_filepost.py

示例3: test_source_address

 def test_source_address(self):
     for addr in VALID_SOURCE_ADDRESSES:
         pool = HTTPConnectionPool(self.host, self.port,
                 source_address=addr, retries=False)
         r = pool.request('GET', '/source_address')
         assert r.data == b(addr[0]), (
             "expected the response to contain the source address {addr}, "
             "but was {data}".format(data=r.data, addr=b(addr[0])))
开发者ID:JasonRepo,项目名称:urllib3,代码行数:8,代码来源:test_connectionpool.py

示例4: test_control_style

 def test_control_style(self):
     fields = [(u('n\u00e4me\u011b'), u('va\u0142u\u00ea'))]
     encoded, content_type = encode_multipart_formdata(
         fields, boundary=BOUNDARY, field_encoding_style = 'RFC2231')
     self.assertEquals(encoded,
         b'--' + b(BOUNDARY) + b'\r\n'
         b"Content-Disposition: form-data; name*=utf-8''n%C3%A4me%C4%9B\r\n"
         b'\r\n'
         b'va\xc5\x82u\xc3\xaa\r\n'
         b'--' + b(BOUNDARY) + b'--\r\n'
         )
开发者ID:msrajan,项目名称:urllib3,代码行数:11,代码来源:test_filepost.py

示例5: test_control_encoding

 def test_control_encoding(self):
     fields = [(u('n\u00e4me\u011b'), u('va\u0142u\u00ea'))]
     encoded, content_type = encode_multipart_formdata(
         fields, boundary=BOUNDARY, form_data_encoding = 'iso-8859-1')
     self.assertEquals(encoded,
         b'--' + b(BOUNDARY) + b'\r\n'
         b'Content-Disposition: form-data; name="n\xe4meě"\r\n'
         b'\r\n'
         b'vału\xea\r\n'
         b'--' + b(BOUNDARY) + b'--\r\n'
         )
开发者ID:msrajan,项目名称:urllib3,代码行数:11,代码来源:test_filepost.py

示例6: test_source_address

 def test_source_address(self):
     for addr, is_ipv6 in VALID_SOURCE_ADDRESSES:
         if is_ipv6 and not HAS_IPV6_AND_DNS:
             warnings.warn("No IPv6 support: skipping.", NoIPv6Warning)
             continue
         pool = HTTPConnectionPool(self.host, self.port, source_address=addr, retries=False)
         r = pool.request("GET", "/source_address")
         assert r.data == b(addr[0]), (
             "expected the response to contain the source address {addr}, "
             "but was {data}".format(data=r.data, addr=b(addr[0]))
         )
开发者ID:aliyun,项目名称:aliyun-tablestore-tutorials,代码行数:11,代码来源:test_connectionpool.py

示例7: test_request_fields

    def test_request_fields(self):
      fields = [RequestField('k', b'v', filename='somefile.txt', headers={'Content-Type': 'image/jpeg'})]

      encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)

      self.assertEqual(encoded,
          b'--' + b(BOUNDARY) + b'\r\n'
          b'Content-Type: image/jpeg\r\n'
          b'\r\n'
          b'v\r\n'
          b'--' + b(BOUNDARY) + b'--\r\n'
          )
开发者ID:ANKIT-KS,项目名称:fjord,代码行数:12,代码来源:test_filepost.py

示例8: test_explicit

    def test_explicit(self):
        fields = [('k', ('somefile.txt', b'v', 'image/jpeg'))]

        encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
        expected = (b'--' + b(BOUNDARY) + b'\r\n'
                    b'Content-Disposition: form-data; name="k"; filename="somefile.txt"\r\n'
                    b'Content-Type: image/jpeg\r\n'
                    b'\r\n'
                    b'v\r\n'
                    b'--' + b(BOUNDARY) + b'--\r\n')

        assert encoded == expected

        assert content_type == 'multipart/form-data; boundary=' + str(BOUNDARY)
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:14,代码来源:test_filepost.py

示例9: test_filename

    def test_filename(self):
        fields = [('k', ('somename', b'v'))]

        encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
        expected = (b'--' + b(BOUNDARY) + b'\r\n'
                    b'Content-Disposition: form-data; name="k"; filename="somename"\r\n'
                    b'Content-Type: application/octet-stream\r\n'
                    b'\r\n'
                    b'v\r\n'
                    b'--' + b(BOUNDARY) + b'--\r\n')

        assert encoded == expected

        assert content_type == 'multipart/form-data; boundary=' + str(BOUNDARY)
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:14,代码来源:test_filepost.py

示例10: test_field_encoding

    def test_field_encoding(self, fields):
        encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
        expected = (b'--' + b(BOUNDARY) + b'\r\n'
                    b'Content-Disposition: form-data; name="k"\r\n'
                    b'\r\n'
                    b'v\r\n'
                    b'--' + b(BOUNDARY) + b'\r\n'
                    b'Content-Disposition: form-data; name="k2"\r\n'
                    b'\r\n'
                    b'v2\r\n'
                    b'--' + b(BOUNDARY) + b'--\r\n')

        assert encoded == expected

        assert content_type == 'multipart/form-data; boundary=' + str(BOUNDARY)
开发者ID:NickMinnellaCS96,项目名称:urllib3,代码行数:15,代码来源:test_filepost.py

示例11: test_textplain

    def test_textplain(self):
        fields = [('k', ('somefile.txt', b'v'))]

        encoded, content_type = encode_multipart_formdata(fields, boundary=BOUNDARY)
        expected = (b'--' + b(BOUNDARY) + b'\r\n'
                    b'Content-Disposition: form-data; name="k"; filename="somefile.txt"\r\n'
                    b'Content-Type: text/plain\r\n'
                    b'\r\n'
                    b'v\r\n'
                    b'--' + b(BOUNDARY) + b'--\r\n')

        self.assertEqual(encoded, expected)

        self.assertEqual(content_type,
                         'multipart/form-data; boundary=' + str(BOUNDARY))
开发者ID:Lukasa,项目名称:urllib3,代码行数:15,代码来源:test_filepost.py

示例12: test_source_address

 def test_source_address(self):
     for addr in VALID_SOURCE_ADDRESSES:
         https_pool = HTTPSConnectionPool(
             self.host, self.port, cert_reqs='CERT_REQUIRED',
             source_address=addr)
         https_pool.ca_certs = DEFAULT_CA
         r = https_pool.request('GET', '/source_address')
         assert r.data == b(addr[0])
开发者ID:iyed,项目名称:urllib3,代码行数:8,代码来源:test_https.py

示例13: test_input_datastructures

    def test_input_datastructures(self):
        fieldsets = [
            dict(k='v', k2='v2'),
            [('k', 'v'), ('k2', 'v2')],
        ]

        for fields in fieldsets:
            encoded, _ = encode_multipart_formdata(fields, boundary=BOUNDARY)
            self.assertEqual(encoded.count(b(BOUNDARY)), 3)
开发者ID:msrajan,项目名称:urllib3,代码行数:9,代码来源:test_filepost.py

示例14: test_source_address

 def test_source_address(self):
     for addr, is_ipv6 in VALID_SOURCE_ADDRESSES:
         if is_ipv6 and not HAS_IPV6_AND_DNS:
             warnings.warn("No IPv6 support: skipping.",
                           NoIPv6Warning)
             continue
         pool = HTTPConnectionPool(self.host, self.port,
                 source_address=addr, retries=False)
         r = pool.request('GET', '/source_address')
         self.assertEqual(r.data, b(addr[0]))
开发者ID:Altynai,项目名称:urllib3,代码行数:10,代码来源:test_connectionpool.py

示例15: test_source_address

 def test_source_address(self):
     for addr in VALID_SOURCE_ADDRESSES:
         pool = HTTPConnectionPool(
             self.host, self.port, source_address=addr)
         r = pool.request('GET', '/source_address')
         assert r.data == b(addr[0])
开发者ID:gruns,项目名称:urllib3,代码行数:6,代码来源:test_connectionpool.py


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