Make this a pure-ASCII file. This used to have a Latin-1 coding and

contain several string literals using non-ASCII characters.  Because
of the pain of displaying those characters, it's better to use \xXX
escapes for these instead of typing the accented characters.

Apologies if I missed something; it didn't look like there was anything
that depended on this file being encoded in Latin-1 or containing non-ASCII
characters.
This commit is contained in:
Guido van Rossum 2007-07-12 09:25:21 +00:00
parent fc0ffb7243
commit e409b97950
1 changed files with 11 additions and 12 deletions

View File

@ -1,4 +1,3 @@
# coding: latin-1
import unittest
import ctypes
@ -27,14 +26,14 @@ else:
self.failUnlessEqual(wcslen("ab\u2070"), 3)
# string args are converted
self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessRaises(ctypes.ArgumentError, wcslen, "abä")
self.failUnlessRaises(ctypes.ArgumentError, wcslen, "ab\xe4")
def test_ascii_replace(self):
ctypes.set_conversion_mode("ascii", "replace")
self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen("ab\u2070"), 3)
self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen("abä"), 3)
self.failUnlessEqual(wcslen("ab\xe4"), 3)
def test_ascii_ignore(self):
ctypes.set_conversion_mode("ascii", "ignore")
@ -42,14 +41,14 @@ else:
self.failUnlessEqual(wcslen("ab\u2070"), 3)
# ignore error mode skips non-ascii characters
self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen("äöüß"), 0)
self.failUnlessEqual(wcslen("\xe4\xf6\xfc\xdf"), 0)
def test_latin1_strict(self):
ctypes.set_conversion_mode("latin-1", "strict")
self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen("ab\u2070"), 3)
self.failUnlessEqual(wcslen("abc"), 3)
self.failUnlessEqual(wcslen("äöüß"), 4)
self.failUnlessEqual(wcslen("\xe4\xf6\xfc\xdf"), 4)
def test_buffers(self):
ctypes.set_conversion_mode("ascii", "strict")
@ -57,11 +56,11 @@ else:
self.failUnlessEqual(len(buf), 3+1)
ctypes.set_conversion_mode("ascii", "replace")
buf = ctypes.create_unicode_buffer("abäöü")
buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc")
self.failUnlessEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0")
ctypes.set_conversion_mode("ascii", "ignore")
buf = ctypes.create_unicode_buffer("abäöü")
buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc")
# is that correct? not sure. But with 'ignore', you get what you pay for..
self.failUnlessEqual(buf[:], "ab\0\0\0\0")
@ -83,19 +82,19 @@ else:
ctypes.set_conversion_mode("ascii", "strict")
self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func("abc"), "abc")
self.assertRaises(ctypes.ArgumentError, func, "abä")
self.assertRaises(ctypes.ArgumentError, func, "ab\xe4")
def test_ascii_ignore(self):
ctypes.set_conversion_mode("ascii", "ignore")
self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func("äöüß"), "")
self.failUnlessEqual(func("\xe4\xf6\xfc\xdf"), "")
def test_ascii_replace(self):
ctypes.set_conversion_mode("ascii", "replace")
self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func("abc"), "abc")
self.failUnlessEqual(func("äöüß"), "????")
self.failUnlessEqual(func("\xe4\xf6\xfc\xdf"), "????")
def test_buffers(self):
ctypes.set_conversion_mode("ascii", "strict")
@ -103,11 +102,11 @@ else:
self.failUnlessEqual(len(buf), 3+1)
ctypes.set_conversion_mode("ascii", "replace")
buf = ctypes.create_string_buffer("abäöü")
buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc")
self.failUnlessEqual(buf[:], "ab???\0")
ctypes.set_conversion_mode("ascii", "ignore")
buf = ctypes.create_string_buffer("abäöü")
buf = ctypes.create_string_buffer("ab\xe4\xf6\xfc")
# is that correct? not sure. But with 'ignore', you get what you pay for..
self.failUnlessEqual(buf[:], "ab\0\0\0\0")