New issue 3074: compile() fails on non-ascii filename if LANG=C
https://bitbucket.org/pypy/pypy/issues/3074/compile-fails-on-non-ascii-filename-if

Ned Batchelder:

Setting LANG=C sets getfilesystemencoding to ‘ascii’.  In CPython, and PyPy 
before 7.1.1, compile\(\) could still compile a non-ascii filename.  Now in 
PyPy3 7.1.1, compile\(\) fails in this situation.

Reproduction:

```
$ cat weird_file.py
import sys
print("\n--- {} --------------".format(sys.executable))
print(sys.version)
print("sys.getfilesystemencoding(): {!r}".format(sys.getfilesystemencoding()))
globs = {}
code = "a = 1\n"
exec(compile(code, "wut\xe9\xea\xeb\xec\x01\x02.py", 'exec'), globs)
print(globs['a'])

$ for py in /usr/local/bin/{python,pypy}*; do LANG=C $py weird_file.py; done

--- /usr/local/bin/python2.7 --------------
2.7.14 (default, Oct  4 2017, 09:45:53)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.1 --------------
3.1.5 (default, Jun 18 2016, 17:54:07)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.2 --------------
3.2.6 (default, Jun 18 2016, 17:56:34)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.3 --------------
3.3.6 (default, Jun 18 2016, 17:58:30)
[GCC 4.2.1 Compatible Apple LLVM 7.0.2 (clang-700.1.81)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.4 --------------
3.4.8 (default, Feb 19 2018, 09:34:36)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.5 --------------
3.5.5 (default, Feb 19 2018, 09:28:14)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.6 --------------
3.6.9 (default, Jul 29 2019, 08:21:55)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.10.44.4)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.7 --------------
3.7.4 (default, Jul 11 2019, 19:53:42)
[Clang 10.0.0 (clang-1000.10.44.4)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/python3.8 --------------
3.8.0b4 (default, Aug 30 2019, 06:51:19)
[Clang 10.0.0 (clang-1000.10.44.4)]
sys.getfilesystemencoding(): 'utf-8'
1

--- /usr/local/bin/pypy6.0 --------------
2.7.13 (ab0b9caf307d, Apr 24 2018, 18:05:02)
[PyPy 6.0.0 with GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
sys.getfilesystemencoding(): 'US-ASCII'
1

--- /usr/local/bin/pypy7.0 --------------
2.7.13 (9112c8071614, Feb 05 2019, 13:50:20)
[PyPy 7.0.0 with GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]
sys.getfilesystemencoding(): 'US-ASCII'
1

--- /usr/local/bin/pypy7.1 --------------
2.7.13 (8cdda8b8cdb8, Apr 14 2019, 14:06:58)
[PyPy 7.1.1 with GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]
sys.getfilesystemencoding(): 'US-ASCII'
1

--- /usr/local/bin/pypy3-6.0 --------------
3.5.3 (fdd60ed87e94, Apr 24 2018, 06:10:18)
[PyPy 6.0.0 with GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1)]
sys.getfilesystemencoding(): 'ascii'
1

--- /usr/local/bin/pypy3-7.0 --------------
3.5.3 (928a4f70d3de, Feb 08 2019, 10:43:14)
[PyPy 7.0.0 with GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.5)]
sys.getfilesystemencoding(): 'ascii'
1

--- /usr/local/bin/pypy3-7.1 --------------
3.6.1 (784b254d6699, Apr 14 2019, 10:22:55)
[PyPy 7.1.1-beta0 with GCC 4.2.1 Compatible Apple LLVM 10.0.0 
(clang-1000.11.45.5)]
sys.getfilesystemencoding(): 'ascii'
Traceback (most recent call last):
  File "weird_file.py", line 7, in <module>
    exec(compile(code, "wut\xe9\xea\xeb\xec\x01\x02.py", 'exec'), globs)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 3-6: 
ordinal not in range(128)

$
```

‌


_______________________________________________
pypy-issue mailing list
pypy-issue@python.org
https://mail.python.org/mailman/listinfo/pypy-issue

Reply via email to