當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。