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


Python ctypes.set_conversion_mode方法代码示例

本文整理汇总了Python中ctypes.set_conversion_mode方法的典型用法代码示例。如果您正苦于以下问题:Python ctypes.set_conversion_mode方法的具体用法?Python ctypes.set_conversion_mode怎么用?Python ctypes.set_conversion_mode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ctypes的用法示例。


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

示例1: test_buffers

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_buffers(self):
        ctypes.set_conversion_mode("ascii", "strict")
        buf = ctypes.create_unicode_buffer("abc")
        self.assertEqual(len(buf), 3+1)

        ctypes.set_conversion_mode("ascii", "replace")
        buf = ctypes.create_unicode_buffer("ab���")
        self.assertEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0")
        self.assertEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0")
        self.assertEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba")
        self.assertEqual(buf[::2], u"a\uFFFD\uFFFD")
        self.assertEqual(buf[6:5:-1], u"")

        ctypes.set_conversion_mode("ascii", "ignore")
        buf = ctypes.create_unicode_buffer("ab���")
        # is that correct? not sure.  But with 'ignore', you get what you pay for..
        self.assertEqual(buf[:], u"ab\0\0\0\0")
        self.assertEqual(buf[::], u"ab\0\0\0\0")
        self.assertEqual(buf[::-1], u"\0\0\0\0ba")
        self.assertEqual(buf[::2], u"a\0\0")
        self.assertEqual(buf[6:5:-1], u"") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_unicode.py

示例2: test_buffers

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_buffers(self):
            ctypes.set_conversion_mode("ascii", "strict")
            buf = ctypes.create_unicode_buffer("abc")
            self.assertEqual(len(buf), 3+1)

            ctypes.set_conversion_mode("ascii", "replace")
            buf = ctypes.create_unicode_buffer("ab���")
            self.assertEqual(buf[:], u"ab\uFFFD\uFFFD\uFFFD\0")
            self.assertEqual(buf[::], u"ab\uFFFD\uFFFD\uFFFD\0")
            self.assertEqual(buf[::-1], u"\0\uFFFD\uFFFD\uFFFDba")
            self.assertEqual(buf[::2], u"a\uFFFD\uFFFD")
            self.assertEqual(buf[6:5:-1], u"")

            ctypes.set_conversion_mode("ascii", "ignore")
            buf = ctypes.create_unicode_buffer("ab���")
            # is that correct? not sure.  But with 'ignore', you get what you pay for..
            self.assertEqual(buf[:], u"ab\0\0\0\0")
            self.assertEqual(buf[::], u"ab\0\0\0\0")
            self.assertEqual(buf[::-1], u"\0\0\0\0ba")
            self.assertEqual(buf[::2], u"a\0\0")
            self.assertEqual(buf[6:5:-1], u"") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_unicode.py

示例3: setUp

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def setUp(self):
        self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_unicode.py

示例4: tearDown

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def tearDown(self):
        ctypes.set_conversion_mode(*self.prev_conv_mode) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:4,代码来源:test_unicode.py

示例5: test_ascii_strict

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_ascii_strict(self):
        wcslen = self.wcslen
        ctypes.set_conversion_mode("ascii", "strict")
        # no conversions take place with unicode arguments
        self.assertEqual(wcslen(u"abc"), 3)
        self.assertEqual(wcslen(u"ab\u2070"), 3)
        # string args are converted
        self.assertEqual(wcslen("abc"), 3)
        self.assertRaises(ctypes.ArgumentError, wcslen, "ab�") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_unicode.py

示例6: test_ascii_replace

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_ascii_replace(self):
        wcslen = self.wcslen
        ctypes.set_conversion_mode("ascii", "replace")
        self.assertEqual(wcslen(u"abc"), 3)
        self.assertEqual(wcslen(u"ab\u2070"), 3)
        self.assertEqual(wcslen("abc"), 3)
        self.assertEqual(wcslen("ab�"), 3) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:9,代码来源:test_unicode.py

示例7: test_ascii_ignore

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_ascii_ignore(self):
        wcslen = self.wcslen
        ctypes.set_conversion_mode("ascii", "ignore")
        self.assertEqual(wcslen(u"abc"), 3)
        self.assertEqual(wcslen(u"ab\u2070"), 3)
        # ignore error mode skips non-ascii characters
        self.assertEqual(wcslen("abc"), 3)
        self.assertEqual(wcslen("����"), 0) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:10,代码来源:test_unicode.py

示例8: setUp

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def setUp(self):
            self.prev_conv_mode = ctypes.set_conversion_mode("ascii", "strict") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:4,代码来源:test_unicode.py

示例9: tearDown

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def tearDown(self):
            ctypes.set_conversion_mode(*self.prev_conv_mode) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:4,代码来源:test_unicode.py

示例10: test_ascii_strict

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_ascii_strict(self):
            ctypes.set_conversion_mode("ascii", "strict")
            # no conversions take place with unicode arguments
            self.assertEqual(wcslen(u"abc"), 3)
            self.assertEqual(wcslen(u"ab\u2070"), 3)
            # string args are converted
            self.assertEqual(wcslen("abc"), 3)
            self.assertRaises(ctypes.ArgumentError, wcslen, "ab�") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:10,代码来源:test_unicode.py

示例11: test_ascii_replace

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_ascii_replace(self):
            ctypes.set_conversion_mode("ascii", "replace")
            self.assertEqual(wcslen(u"abc"), 3)
            self.assertEqual(wcslen(u"ab\u2070"), 3)
            self.assertEqual(wcslen("abc"), 3)
            self.assertEqual(wcslen("ab�"), 3) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:8,代码来源:test_unicode.py

示例12: test_ascii_ignore

# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def test_ascii_ignore(self):
            ctypes.set_conversion_mode("ascii", "ignore")
            self.assertEqual(wcslen(u"abc"), 3)
            self.assertEqual(wcslen(u"ab\u2070"), 3)
            # ignore error mode skips non-ascii characters
            self.assertEqual(wcslen("abc"), 3)
            self.assertEqual(wcslen("����"), 0) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:9,代码来源:test_unicode.py


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