[New-bugs-announce] [issue8715] Create PyUnicode_EncodeFSDefault() function

STINNER Victor report at bugs.python.org
Fri May 14 18:53:54 CEST 2010

New submission from STINNER Victor <victor.stinner at 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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list