summaryrefslogtreecommitdiffstats
path: root/Lib/ctypes
diff options
context:
space:
mode:
authorThomas Heller <theller@ctypes.org>2007-07-12 19:06:25 (GMT)
committerThomas Heller <theller@ctypes.org>2007-07-12 19:06:25 (GMT)
commit60831316df8893e973f92592b7c4c95ad489ff15 (patch)
tree6e788f97e7c2874b12540a1cb30c946896efb926 /Lib/ctypes
parentd0762282022ebb9809e488325cf86bb71e1371c0 (diff)
downloadcpython-60831316df8893e973f92592b7c4c95ad489ff15.zip
cpython-60831316df8893e973f92592b7c4c95ad489ff15.tar.gz
cpython-60831316df8893e973f92592b7c4c95ad489ff15.tar.bz2
Accept bytes for c_wchar_p instances and c_wchar array instances.
ctypes.create_unicode_buffer also accepts bytes now. Revert some tests in test_unicode: Since string literals are unicode now, conversion takes place when byte literals are passed as unicode parameters.
Diffstat (limited to 'Lib/ctypes')
-rw-r--r--Lib/ctypes/__init__.py2
-rw-r--r--Lib/ctypes/test/test_unicode.py8
2 files changed, 5 insertions, 5 deletions
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index 8c9fe1a..86678ea 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -281,7 +281,7 @@ else:
create_unicode_buffer(anInteger) -> character array
create_unicode_buffer(aString, anInteger) -> character array
"""
- if isinstance(init, str):
+ if isinstance(init, (str, bytes)):
if size is None:
size = len(init)+1
buftype = c_wchar * size
diff --git a/Lib/ctypes/test/test_unicode.py b/Lib/ctypes/test/test_unicode.py
index 3a89d8d..bf5486c 100644
--- a/Lib/ctypes/test/test_unicode.py
+++ b/Lib/ctypes/test/test_unicode.py
@@ -26,7 +26,7 @@ else:
self.failUnlessEqual(wcslen("ab\u2070"), 3)
# string args are converted
self.failUnlessEqual(wcslen("abc"), 3)
- self.failUnlessRaises(ctypes.ArgumentError, wcslen, "ab\xe4")
+ self.failUnlessRaises(ctypes.ArgumentError, wcslen, b"ab\xe4")
def test_ascii_replace(self):
ctypes.set_conversion_mode("ascii", "replace")
@@ -41,7 +41,7 @@ else:
self.failUnlessEqual(wcslen("ab\u2070"), 3)
# ignore error mode skips non-ascii characters
self.failUnlessEqual(wcslen("abc"), 3)
- self.failUnlessEqual(wcslen("\xe4\xf6\xfc\xdf"), 0)
+ self.failUnlessEqual(wcslen(b"\xe4\xf6\xfc\xdf"), 0)
def test_latin1_strict(self):
ctypes.set_conversion_mode("latin-1", "strict")
@@ -56,11 +56,11 @@ else:
self.failUnlessEqual(len(buf), 3+1)
ctypes.set_conversion_mode("ascii", "replace")
- buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc")
+ buf = ctypes.create_unicode_buffer(b"ab\xe4\xf6\xfc")
self.failUnlessEqual(buf[:], "ab\uFFFD\uFFFD\uFFFD\0")
ctypes.set_conversion_mode("ascii", "ignore")
- buf = ctypes.create_unicode_buffer("ab\xe4\xf6\xfc")
+ buf = ctypes.create_unicode_buffer(b"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")