New submission from STINNER Victor <victor.stin...@haypocalc.com>: PyUnicode_EncodeFSDefault() is the opposite of PyUnicode_DecodeFSDefault(AndSize)() and is similar to the new function os.fsencode(). As you can see in the patch, it simplifies many functions.
/* Encodes a Unicode object to Py_FileSystemDefaultEncoding with the "surrogateescape" error handler and returns a bytes object. If Py_FileSystemDefaultEncoding is not set, fall back to UTF-8. */ PyAPI_FUNC(PyObject*) PyUnicode_EncodeFSDefault( PyObject *unicode ); The function unify the behaviour when Py_FileSystemDefaultEncoding is NULL: use UTF-8 whereas import uses ASCII. Other functions did already fall back to UTF-8: PyUnicode_AsEncodedString() uses PyUnicode_GetDefaultEncoding() (hardcoded to utf8 in Python3) if encoding is NULL The patch does also fix tkinter module initializer (use surrogateescape error handler, instead of strict). The patch was first attached to issue #8611. ---------- components: Interpreter Core, Unicode files: pyunicode_encodefsdefault-2.patch keywords: patch messages: 105721 nosy: Arfrever, benjamin.peterson, ezio.melotti, gregory.p.smith, haypo, lemburg, loewis, pitrou priority: normal severity: normal status: open title: Create PyUnicode_EncodeFSDefault() function versions: Python 3.2 Added file: http://bugs.python.org/file17340/pyunicode_encodefsdefault-2.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8715> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com