[1.7][python] File operation API to multibyte filenames fails.

IWAMURO Motonori deenheart@gmail.com
Fri May 8 13:02:00 GMT 2009


File operation API to multibyte filenames fails on Python and Cygwin-1.7.
Which Python or Cygwin-1.7 should be fixed?

My environment: Windows XP SP3, Cygwin-1.7.0-46, and LANG=ja_JP.UTF-8

The following code fails on the directory which has multibyte filenames:

>>> import os
>>> os.listdir(".")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 138] Invalid or incomplete multibyte or wide character: '.'

The following code works correctly:

>>> import os
>>> import locale
>>> locale.setlocale(locale.LC_CTYPE, '')
>>> os.listdir(".")
[(snip), '\xe3\x82\xb9\xe3\x82\xbf\xe3\x83\xbc\xe3\x83\x88

However, it is impossible to fix all the python scripts.

There are two causes.

- Python has intentionally evaded the execution of setlocale(LC_ALL,
"") and/or setlocale(LC_CTYPE, "").
- When locale is not appropriately set, Cygwin-1.7 converts non-ASCII
character into a special sequence. (see "Convert chars invalid in the
current codepage to a sequence ASCII SO" part of sys_cp_wcstombs in

Which Python or Cygwin-1.7 should be fixed?
IWAMURO Motnori <http://vmi.jp/>

Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

More information about the Cygwin mailing list