New submission from STINNER Victor:

The Python C API has two very useful functions: _Py_char2wchar() and 
_Py_wchar2char(). They must be used to handle correctly undecodable byte 
sequences. _Py_char2wchar() and _Py_wchar2char() use the surrogateescape error 
handler (PEP 383). _Py_char2wchar() forces also the ASCII encoding on FreeBSD 
and Solaris when the LC_CTYPE locale is C.

Py_Main() expects an array of wide character strings (wchar_t*) for the command 
line argument, whereas main() gets an array or byte strings (char*). 
_Py_char2wchar() must be used to be able to call Py_Main().

I propose the following names:

wchar_t* Py_DecodeLocale(const char* arg, size_t *size);
char* Py_EncodeLocale(const wchar_t *text, size_t *error_pos);

See Python/fileutils.c for more information about these functions.


Python 3.3 has already higher level functions (calling _Py_char2_wchar() and 
_Py_wchar2char()):

PyObject* PyUnicode_DecodeLocale(const char *str, const char *errors);
PyObject* PyUnicode_EncodeLocale(PyObject *unicode, const char *errors);

But these functions cannot be used before Python is initialized.

----------
messages: 192557
nosy: haypo
priority: normal
severity: normal
status: open
title: Make _Py_char2wchar() and _Py_wchar2char() public
versions: Python 3.4

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue18395>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to