[issue9542] Create PyUnicode_FSDecoder() function

STINNER Victor report at bugs.python.org
Fri Aug 13 03:47:36 CEST 2010


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

Lib/os.py may also be patched to add a Python implementation. Eg.

def fsdecode(value):
    if isinstance(value, str):
        return value
    elif isinstance(value, bytes):
        encoding = sys.getfilesystemencoding()
        if encoding == 'mbcs':
            return value.decode(encoding)
        else:
            return value.decode(encoding, 'surrogateescape')
    else:
        raise TypeError("expect bytes or str, not %s" % type(value).__name__)

--

Note: Solution (1) (use bytes API) is not deprecated by this issue. PyUnicode_FSConverter is still useful if the underlying library has a bytes API (eg. OpenSSL only supports char*).

Solution (2) is preferred if we have access to a character API, eg. Windows wide character API.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9542>
_______________________________________


More information about the Python-bugs-list mailing list