[Python-Dev] Use our strict mbcs codec instead of the Windows ANSI API

Victor Stinner victor.stinner at haypocalc.com
Tue Oct 25 10:31:56 CEST 2011


Le Mardi 25 Octobre 2011 09:09:56 vous avez écrit :
> > I propose to raise Unicode errors if a filename cannot be decoded on
> > Windows, instead of creating a bogus filenames with questions marks.
> 
> Can you please elaborate what APIs you are talking about exactly?

Basically, all functions processing filenames, so most functions of 
posixmodule.c. Some examples:

- os.listdir(): FindFirstFileA, FindNextFileA, FindCloseA
- os.lstat(): CreateFileA
- os.getcwdb(): getcwd()
- os.mkdir(): CreateDirectoryA
- os.chmod(): SetFileAttributesA
- ...

> If it's the byte APIs (i.e. using bytes as file names), then I'm -1 on
> this proposal. People that explicitly use bytes for file names deserve
> to get whatever exact platform semantics the platform has to offer. This
> is true on Unix, and it is also true on Windows.

My proposition is a fix to user reported by a user:
http://bugs.python.org/issue13247

I want to keep the bytes API for backward compatibility, and it will still 
work for non-ASCII characters, but only for non-ASCII characters encodable to 
the ANSI code page.

In practice, characters not encodable to the ANSI code page are very rare. For 
example: it's difficult to write such characters directly with the keyboard. I 
bet that very few people will notify the change.

Victor


More information about the Python-Dev mailing list