[New-bugs-announce] [issue8514] Create fs_encode() and fs_decode() functions in os.path

STINNER Victor report at bugs.python.org
Sat Apr 24 01:39:12 CEST 2010


New submission from STINNER Victor <victor.stinner at haypocalc.com>:

Python3 uses unicode filenames in Windows and bytes filenames (but support also unicode filenames) on other OS. We have to support both types. On POSIX system, bytes filenames can be stored in unicode filenames using sys.getfilesystemencoding() and the surrogateescape error handler (to store undecodable bytes as unicode surrogates, see PEP 383).

I would like to create fs_encode() and fs_decode() in os.path to ease the manipulation of filenames in the two bytes (str and bytes).
 * Use fs_decode() to convert a filename from the OS native format to unicode
 * Use fs_encode() to convert an unicode filename to the OS native format

On Windows, fs_decode() and fs_encode() don't touch the filename, but reject filenames of types different than str (unicode) with a TypeError, especially bytes filename.

Mac OS X rejects invalid UTF-8 filenames, and so surrogateescape should maybe not be used on this OS.

Attached patch is an implementation of this issue.

----------
components: Library (Lib), Unicode
files: os_path_fs_encode_decode.patch
keywords: patch
messages: 104063
nosy: haypo
severity: normal
status: open
title: Create fs_encode() and fs_decode() functions in os.path
versions: Python 3.2
Added file: http://bugs.python.org/file17061/os_path_fs_encode_decode.patch

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


More information about the New-bugs-announce mailing list