[issue3187] os.listdir can return byte strings

STINNER Victor report at bugs.python.org
Wed Oct 1 00:02:32 CEST 2008


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

As I wrote, python3_bytes_filename.patch was just an initial support 
for bytes filename. So as asked by Guido, here is a new version of my 
patch.

Changes:
 - for all functions, support bytes as well as bytearray
 - os.readlink(unicode) -> unicode and raise an error if unicode 
conversion fails. Note: os.readlink(bytes)->bytes was already working.
 - many changes in posixpath to fix all functions: add many "if 
isinstance(...):" and repeat sep / curdir / parent / ... in bytes
 - current version of test_posixpath contains a duplicate to 
test_splitdrive() and test_normcase() calls normcase() twice which is 
wrong (fixed in my patch)
 - i used copy/paste + conversion to bytes to test posixpath with 
bytes arguments
 - i added some checks in posixpath tests to reject mixing bytes + str
 - fix quoting style
 - factorize pattern compilation in fnmatch
 - fnmatch.fnmatchcase() supports bytes
 - fix test_unicode_file: replace getcwdu() by getcwd(), and sometimes 
getcwd() by getcwdb()

Open issues:
 - pwd.getpwnam() and grp.getgrpnam() should accept bytes, and then
   expanduser() should use pwd with bytes. Now expanduser() 
   supposes that an username is an ASCII string and the user
   directory can be converted using getfilesystemencoding()
 - expandvars() doesn't support non-ASCII variable value:
   that's new problem. os.environ key should be str or bytes?
   And the value: str or bytes? It str is choosen, what is the
   charset to convert str to bytes?

Added file: http://bugs.python.org/file11667/python3_bytes_filename-2.patch

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


More information about the Python-bugs-list mailing list