[Python-Dev] Patch for an initial support of bytes filename in Python3
Victor Stinner
victor.stinner at haypocalc.com
Tue Sep 30 02:47:20 CEST 2008
Hi,
See attached patch: python3_bytes_filename.patch
Using the patch, you will get:
- open() support bytes
- listdir(unicode) -> only unicode, *skip* invalid filenames
(as asked by Guido)
- remove os.getcwdu()
- create os.getcwdb() -> bytes
- glob.glob() support bytes
- fnmatch.filter() support bytes
- posixpath.join() and posixpath.split() support bytes
Mixing bytes and str is invalid. Examples raising a TypeError:
- posixpath.join(b'x', 'y')
- fnmatch.filter([b'x', 'y'], '*')
- fnmatch.filter([b'x', b'y'], '*')
- glob.glob1('.', b'*')
- glob.glob1(b'.', '*')
$ diffstat ~/python3_bytes_filename.patch
Lib/fnmatch.py | 7 +++-
Lib/glob.py | 15 ++++++---
Lib/io.py | 2 -
Lib/posixpath.py | 20 ++++++++----
Modules/posixmodule.c | 83
++++++++++++++++++--------------------------------
5 files changed, 62 insertions(+), 65 deletions(-)
TODO:
- review this patch :-)
- support non-ASCII bytes in fnmatch.filter()
- fix other functions, eg. posixpath.isabs() and fnmatch.fnmatchcase()
- fix functions written in C: grep FileSystemDefaultEncoding
- make sure that mixing bytes and str is rejected
--
Victor Stinner aka haypo
http://www.haypocalc.com/blog/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python3_bytes_filename.patch
Type: text/x-diff
Size: 6732 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-dev/attachments/20080930/e8998338/attachment.patch>
More information about the Python-Dev
mailing list