[Python-Dev] Unicode strings as filenames

Neil Hodgson nhodgson@bigpond.net.au
Sun, 6 Jan 2002 12:47:43 +1100


Martin v. Loewis:

> Now that you have that change, please try to extend it to
> posixmodule.c. This is where I gave up.

   OK. os.open, os.stat, and os.listdir now work. Placed temporarily at
http://pythoncard.sourceforge.net/posixmodule.c

   os.stat is ugly because the posix_do_stat function is parameterised over
a stat function pointer but it is always _stati64 on Windows so the patch
just assumes _wstati64 is right. os.listdir returns Unicode objects rather
than strings. This makes glob.glob work as well so my earlier script that
finds the *.html files and opens them works. Unfortunately, I expect most
callers of glob() will be expecting narrow strings.

> Notice that, with changing
> Py_FileSystemDefaultEncoding and open() alone, you have worsened the
> situation: os.stat will now fail on files with non-ASCII names on
> which it works under the mbcs encoding, because windows won't find the
> file (correct me if I'm wrong).

   If you give it a file name encoded in the current code page then it may
fail where it did not before.

   Neil