[Python-3000] New proposition for Python3 bytes filename issue
Victor Stinner
victor.stinner at haypocalc.com
Mon Sep 29 14:07:55 CEST 2008
Hi,
After reading the previous discussion, here is new proposition.
Python 2.x and Windows are not affected by this issue. Only Python3 on POSIX
(eg. Linux or *BSD) is affected.
Some system are broken, but Python have to be able to open/copy/move/remove
files with an "invalid filename".
The issue can wait for Python 3.0.1 / 3.1.
Windows
-------
On Windows, we might reject bytes filenames for all file operations: open(),
unlink(), os.path.join(), etc. (raise a TypeError or UnicodeError)
POSIX OS
--------
The default behaviour should be to use unicode and raise an error if
conversion to unicode fails. It should also be possible to use bytes using
bytes arguments and optional arguments (for getcwd).
- listdir(unicode) -> unicode and raise an error on invalid filename
- listdir(bytes) -> bytes
- getcwd() -> unicode
- getcwd(bytes=True) -> bytes
- open(): accept bytes or unicode
os.path.*() should accept operations on bytes filenames, but maybe not on
bytes+unicode arguments. os.path.join('directory', b'filename'): raise an
error (or use *implicit* conversion to bytes)?
When the user wants to display a filename to the screen, he can uses:
text = str(filename, fs_encoding, "replace")
--
Victor Stinner aka haypo
http://www.haypocalc.com/blog/
More information about the Python-3000
mailing list