diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-07-28 00:15:03 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-07-28 00:15:03 (GMT) |
commit | cf448832ebca7ed34809168660fa96c3c61f8abb (patch) | |
tree | 2f288bff5d59676d902953a12b16a22de0d1045f /Lib/ctypes/__init__.py | |
parent | 42746df17bd1f147f1bea90216ed9848efc730c8 (diff) | |
download | cpython-cf448832ebca7ed34809168660fa96c3c61f8abb.zip cpython-cf448832ebca7ed34809168660fa96c3c61f8abb.tar.gz cpython-cf448832ebca7ed34809168660fa96c3c61f8abb.tar.bz2 |
Issue #8966: ctypes: Remove implicit bytes-unicode conversion
Diffstat (limited to 'Lib/ctypes/__init__.py')
-rw-r--r-- | Lib/ctypes/__init__.py | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py index ce1d779..71686e7 100644 --- a/Lib/ctypes/__init__.py +++ b/Lib/ctypes/__init__.py @@ -259,41 +259,31 @@ class c_bool(_SimpleCData): from _ctypes import POINTER, pointer, _pointer_type_cache -try: - from _ctypes import set_conversion_mode -except ImportError: - pass -else: - if _os.name in ("nt", "ce"): - set_conversion_mode("mbcs", "strict") - else: - set_conversion_mode("ascii", "strict") +class c_wchar_p(_SimpleCData): + _type_ = "Z" - class c_wchar_p(_SimpleCData): - _type_ = "Z" +class c_wchar(_SimpleCData): + _type_ = "u" - class c_wchar(_SimpleCData): - _type_ = "u" +POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param - POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param - - def create_unicode_buffer(init, size=None): - """create_unicode_buffer(aString) -> character array - create_unicode_buffer(anInteger) -> character array - create_unicode_buffer(aString, anInteger) -> character array - """ - if isinstance(init, (str, bytes)): - if size is None: - size = len(init)+1 - buftype = c_wchar * size - buf = buftype() - buf.value = init - return buf - elif isinstance(init, int): - buftype = c_wchar * init - buf = buftype() - return buf - raise TypeError(init) +def create_unicode_buffer(init, size=None): + """create_unicode_buffer(aString) -> character array + create_unicode_buffer(anInteger) -> character array + create_unicode_buffer(aString, anInteger) -> character array + """ + if isinstance(init, (str, bytes)): + if size is None: + size = len(init)+1 + buftype = c_wchar * size + buf = buftype() + buf.value = init + return buf + elif isinstance(init, int): + buftype = c_wchar * init + buf = buftype() + return buf + raise TypeError(init) POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param |