Author vstinner
Recipients vstinner
Date 2010-04-23.23:39:09
SpamBayes Score 1.85538e-08
Marked as misclassified No
Message-id <1272065952.1.0.987702075651.issue8514@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-04-23 23:39:12vstinnersetrecipients: + vstinner
2010-04-23 23:39:12vstinnersetmessageid: <1272065952.1.0.987702075651.issue8514@psf.upfronthosting.co.za>
2010-04-23 23:39:10vstinnerlinkissue8514 messages
2010-04-23 23:39:10vstinnercreate