本文整理汇总了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"")
示例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"")
示例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")
示例4: tearDown
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def tearDown(self):
ctypes.set_conversion_mode(*self.prev_conv_mode)
示例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�")
示例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)
示例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)
示例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")
示例9: tearDown
# 需要导入模块: import ctypes [as 别名]
# 或者: from ctypes import set_conversion_mode [as 别名]
def tearDown(self):
ctypes.set_conversion_mode(*self.prev_conv_mode)
示例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�")
示例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)
示例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)