STINNER Victor <victor.stin...@haypocalc.com> added the comment:

Use surrogateescape error handler to decode a Windows path is not a good idea. 
On Windows, the problem is not to decode a path (ANSI => wide char), but to 
encode a path (wide char => ANSI) to use a function expecting bytes path 
encoded to the ANSI code page. surrogateescape is only useful on the *decode* 
operation, to store undecodable bytes in special characters.

Why do you decode a Windows path using UTF-8? UTF-8 is not used, by default, as 
an ANSI code page. But first, what do you manipulate bytes path on Windows?

If you would like a portable program supporting UNIX/BSD (bytes) and Windows 
(unicode) paths with a single type, you should use str instead of bytes, 
because Unicode (with surrogateescape) is a superset of bytes.

Python 3.2 has os.fsencode() and os.fsdecode() functions to do that easily (to 
decode/encode UNIX/BSD paths).

----------
nosy: +haypo

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10600>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to