[ctypes-commit] ctypes/ctypes __init__.py,1.38,1.39
Brought to you by:
theller
From: Thomas H. <th...@us...> - 2004-10-11 09:00:10
|
Update of /cvsroot/ctypes/ctypes/ctypes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27621 Modified Files: __init__.py Log Message: Enable unicode on non-windows platforms. Index: __init__.py =================================================================== RCS file: /cvsroot/ctypes/ctypes/ctypes/__init__.py,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** __init__.py 8 Oct 2004 20:17:41 -0000 1.38 --- __init__.py 11 Oct 2004 08:59:50 -0000 1.39 *************** *** 58,81 **** 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, unicode)): - init = unicode(init) - if size is None: - size = len(init)+1 - buftype = c_wchar * size - buf = buftype() - buf.value = init - return buf - elif isinstance(init, (int, long)): - buftype = c_wchar * init - buf = buftype() - return buf - raise TypeError, init - - def c_buffer(init, size=None): ## "deprecated, use create_string_buffer instead" --- 58,61 ---- *************** *** 206,220 **** c_voidp = c_void_p # backwards compatibility (to a bug) - if _os.name == "nt": - class c_wchar_p(_SimpleCData): - _type_ = "Z" - def __repr__(self): - return "%s(%r)" % (self.__class__.__name__, self.value) - - class c_wchar(_SimpleCData): - _type_ = "u" - def __repr__(self): - return "c_wchar(%r)" % self.value - # This cache maps types to pointers to them. from _ctypes import _pointer_type_cache --- 186,189 ---- *************** *** 239,247 **** return klass ! POINTER(c_char).from_param = c_char_p.from_param #_SimpleCData.c_char_p_from_param - if _os.name == "nt": POINTER(c_wchar).from_param = c_wchar_p.from_param #_SimpleCData.c_wchar_p_from_param def SetPointerType(pointer, cls): if _pointer_type_cache.get(cls, None) is not None: --- 208,255 ---- return klass ! try: ! from _ctypes import set_conversion_mode ! except ImportError: ! pass ! else: ! if _os.name == "nt": ! set_conversion_mode("mbcs", "ignore") ! else: ! set_conversion_mode("ascii", "strict") ! ! class c_wchar_p(_SimpleCData): ! _type_ = "Z" ! def __repr__(self): ! return "%s(%r)" % (self.__class__.__name__, self.value) ! ! class c_wchar(_SimpleCData): ! _type_ = "u" ! def __repr__(self): ! return "c_wchar(%r)" % self.value 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, unicode)): + init = unicode(init) + if size is None: + size = len(init)+1 + buftype = c_wchar * size + buf = buftype() + buf.value = init + return buf + elif isinstance(init, (int, long)): + 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 + def SetPointerType(pointer, cls): if _pointer_type_cache.get(cls, None) is not None: *************** *** 369,381 **** return WindowsError(code, descr) - try: - from _ctypes import set_conversion_mode - except ImportError: - pass - else: - if _os.name == "nt": - set_conversion_mode("mbcs", "ignore") - else: - set_conversion_mode("ascii", "strict") - _pointer_type_cache[None] = c_void_p --- 377,379 ---- |