Title: Importation of modules from directories with non-ASCII characters fails
Type: Severity: normal
Components: Core Versions: Jython 2.7
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, jeff.allen, zyasoft
Priority: Keywords:

Created on 2015-03-19.12:41:22 by Arfrever, last changed 2019-07-21.05:55:16 by jeff.allen.

msg9676 (view) Author: Arfrever Frehtes Taifersar Arahesis (Arfrever) Date: 2015-03-19.12:41:22
$ mkdir /tmp/ćśź
$ touch /tmp/ćśź/{a,b}.py
$ cat
# coding: utf-8
import sys
print("sys.path[-1]: %r" % sys.path[-1])
import a
sys.path[-1] = u"/tmp/ćśź"
print("sys.path[-1]: %r" % sys.path[-1])
import b
$ python2.7
sys.path[-1]: '/tmp/\xc4\x87\xc5\x9b\xc5\xba'
<module 'a' from '/tmp/ćśź/'>
sys.path[-1]: u'/tmp/\u0107\u015b\u017a'
<module 'b' from '/tmp/ćśź/'>
$ jython2.7
sys.path[-1]: '/tmp/\xc4\x87\xc5\x9b\xc5\xba'
Traceback (most recent call last):
  File "", line 5, in <module>
    import a
ImportError: No module named a
msg11809 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-16.20:27:56
In Jython 2.7.2a1, this now works:

PS iss2294> jython
sys.path[-1]: '\xc4\x87\xc5\x9b\xc5\xba'
<module 'a' from '膰艣藕\'>
sys.path[-1]: u'\u0107\u015b\u017a'
<module 'b' from '膰艣藕\'>

Or nearly works, apart from the encoding of the directory name for console output. See also #2295.

Interestingly, CPython 2.7.14 fails on my Windows machine:

PS iss2294> python
sys.path[-1]: '\xc4\x87\xc5\x9b\xc5\xba'
Traceback (most recent call last):
  File "", line 8, in <module>
    import a
ImportError: No module named a

This is because the first path actually consists of utf-8 bytes (source encoding) while the FS-encoding is ms936.
msg12480 (view) Author: Jeff Allen (jeff.allen) Date: 2019-05-02.05:50:47
Given the previous comment, I think this should not still be open.
Date User Action Args
2019-07-21 05:55:16jeff.allensetstatus: pending -> closed
2019-05-02 05:50:47jeff.allensetstatus: open -> pending
resolution: fixed
messages: + msg12480
2018-03-16 20:27:57jeff.allensetnosy: + jeff.allen
messages: + msg11809
2015-03-19 12:41:22Arfrevercreate