• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python six.u函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了u函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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_render_part_html5

 def test_render_part_html5(self):
     field = RequestField('somename', 'data')
     field.style = 'HTML5'
     param = field._render_part('filename', u('name'))
     self.assertEqual(param, 'filename="name"')
     param = field._render_part('filename', u('n\u00e4me'))
     self.assertEqual(param, u('filename="n\u00e4me"'))
     param = field._render_part('filename', 'some"really\nbad\\name')
     self.assertEqual(param, 'filename="some\\"really bad\\\\name"')
开发者ID:msrajan,项目名称:urllib3,代码行数:9,代码来源:test_fields.py


示例3: test_render_part_rfc2231

 def test_render_part_rfc2231(self):
     field = RequestField('somename', 'data')
     field.style = 'RFC2231'
     param = field._render_part('filename', u('name'))
     self.assertEqual(param, 'filename="name"')
     param = field._render_part('filename', u('n\u00e4me'))
     self.assertEqual(param, "filename*=utf-8''n%C3%A4me")
     param = field._render_part('filename', 'some"really\nbad\\name')
     self.assertEqual(param, u("filename*=utf-8''some%22really%0Abad%5Cname"))
开发者ID:msrajan,项目名称:urllib3,代码行数:9,代码来源:test_fields.py


示例4: 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


示例5: 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


示例6: _init

    def _init(self, path_to_tx=None):
        instructions = "Run 'tx init' to initialize your project first!"
        try:
            self.root = self._get_tx_dir_path(path_to_tx)
            self.config_file = self._get_config_file_path(self.root)
            self.config = self._read_config_file(self.config_file)

            local_txrc_file = self._get_transifex_file(os.getcwd())
            if os.path.exists(local_txrc_file):
                self.txrc_file = local_txrc_file
            else:
                self.txrc_file = self._get_transifex_file()
            self.txrc = self._get_transifex_config([self.txrc_file, ])
        except ProjectNotInit as e:
            logger.error('\n'.join([six.u(str(e)), instructions]))
            raise
        host = self.config.get('main', 'host')
        if host.lower().startswith('https://'):
            self.conn = urllib3.connection_from_url(
                host,
                cert_reqs=ssl.CERT_REQUIRED,
                ca_certs=certs_file()
            )
        else:
            self.conn = urllib3.connection_from_url(host)
开发者ID:akx,项目名称:transifex-client,代码行数:25,代码来源:project.py


示例7: test_invalid_host

    def test_invalid_host(self):
        # TODO: Add more tests
        invalid_host = [
            'http://google.com:foo',
            'http://::1/',
            'http://::1:80/',
            'http://google.com:-80',
            six.u('http://google.com:\xb2\xb2'),  # \xb2 = ^2
        ]

        for location in invalid_host:
            self.assertRaises(LocationParseError, get_host, location)
开发者ID:Lukasa,项目名称:urllib3,代码行数:12,代码来源:test_util.py


示例8: get_details

def get_details(api_call, username, password, *args, **kwargs):
    """
    Get the tx project info through the API.

    This function can also be used to check the existence of a project.
    """
    url = API_URLS[api_call] % kwargs
    try:
        data, charset = make_request('GET', kwargs['hostname'], url, username, password)
        return parse_json(data)
    except Exception as e:
        logger.debug(six.u(str(e)))
        raise
开发者ID:shimizukawa,项目名称:transifex-client,代码行数:13,代码来源:utils.py


示例9: _get_stats_for_resource

 def _get_stats_for_resource(self):
     """Get the statistics information for a resource."""
     try:
         r, charset = self.do_url_request('resource_stats')
         logger.debug("Statistics response is %s" % r)
         stats = parse_json(r)
     except HttpNotFound:
         logger.debug("Resource not found, creating...")
         stats = {}
     except Exception as e:
         logger.debug(six.u(str(e)))
         raise
     return stats
开发者ID:akx,项目名称:transifex-client,代码行数:13,代码来源:project.py


示例10: test_parse_retry_after

    def test_parse_retry_after(self):
        invalid = [
            "-1",
            "+1",
            "1.0",
            six.u("\xb2"),  # \xb2 = ^2
        ]
        retry = Retry()

        for value in invalid:
            self.assertRaises(InvalidHeader, retry.parse_retry_after, value)

        self.assertEqual(retry.parse_retry_after("0"), 0)
        self.assertEqual(retry.parse_retry_after("1000"), 1000)
        self.assertEqual(retry.parse_retry_after("\t42 "), 42)
开发者ID:Lukasa,项目名称:urllib3,代码行数:15,代码来源:test_util.py


示例11: test_unicode_upload

    def test_unicode_upload(self):
        fieldname = u("myfile")
        filename = u("\xe2\x99\xa5.txt")
        data = u("\xe2\x99\xa5").encode("utf8")
        size = len(data)

        fields = {
            u("upload_param"): fieldname,
            u("upload_filename"): filename,
            u("upload_size"): size,
            fieldname: (filename, data),
        }

        r = self.pool.request("POST", "/upload", fields=fields)
        self.assertEqual(r.status, 200, r.data)
开发者ID:aliyun,项目名称:aliyun-tablestore-tutorials,代码行数:15,代码来源:test_connectionpool.py


示例12: test_render_part_rfc2231_non_ascii

 def test_render_part_rfc2231_non_ascii(self):
     field = RequestFieldRFC2231('somename', 'data')
     param = field._render_part('filename', u('n\u00e4me'))
     self.assertEqual(param, u("filename*=utf-8''n%C3%A4me"))
开发者ID:Spryttan,项目名称:urllib3,代码行数:4,代码来源:test_fields.py


示例13: test_from_tuples_rfc2231

 def test_from_tuples_rfc2231(self):
     field = RequestFieldRFC2231.from_tuples(u('fieldname'), (u('filen\u00e4me'), 'data'))
     cd = field.headers['Content-Disposition']
     self.assertEqual(cd, u("form-data; name=\"fieldname\"; filename*=utf-8''filen%C3%A4me"))
开发者ID:Spryttan,项目名称:urllib3,代码行数:4,代码来源:test_fields.py


示例14: test_render_part_html5

 def test_render_part_html5(self):
     field = RequestField('somename', 'data')
     param = field._render_part('filename', u('n\u00e4me'))
     self.assertEqual(param, u('filename="n\u00e4me"'))
开发者ID:Spryttan,项目名称:urllib3,代码行数:4,代码来源:test_fields.py


示例15: test_render_part

 def test_render_part(self):
     field = RequestField('somename', 'data')
     param = field._render_part('filename', u('n\u00e4me'))
     self.assertEqual(param, "filename*=utf-8''n%C3%A4me")
开发者ID:Altynai,项目名称:urllib3,代码行数:4,代码来源:test_fields.py


示例16: test_from_tuples_html5

 def test_from_tuples_html5(self):
     field = RequestField.from_tuples(u('fieldname'), (u('filen\u00e4me'), 'data'))
     cd = field.headers['Content-Disposition']
     self.assertEqual(cd, u('form-data; name="fieldname"; filename="filen\u00e4me"'))
开发者ID:Spryttan,项目名称:urllib3,代码行数:4,代码来源:test_fields.py


示例17: test_render_part_invalid_style

 def test_render_part_invalid_style(self):
     field = RequestField('somename', 'data')
     field.style = 'ThereIsNoSuchStyle'
     self.assertRaises(NotImplementedError,
         field._render_part, 'filename', u('name'))
开发者ID:msrajan,项目名称:urllib3,代码行数:5,代码来源:test_fields.py


示例18: test_render_part_rfc2231_ascii_only

 def test_render_part_rfc2231_ascii_only(self):
     field = RequestFieldRFC2231('somename', 'data')
     param = field._render_part('filename', u('name'))
     self.assertEqual(param, u('filename="name"'))
开发者ID:Spryttan,项目名称:urllib3,代码行数:4,代码来源:test_fields.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python poolmanager.proxy_from_url函数代码示例发布时间:2022-05-27
下一篇:
Python six.b函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap