Default locale/getpreferredlocale differences on Linux?
Observed with the latest stable
pypy3. Refer to the example
#!/opt/pypy/bin/pypy3 import locale print(locale.getpreferredencoding(False)) with open('/tmp/devpi/test') as f: print(type(f)) f = f.read() print(f, type(f))
File contents of the sample file don't matter, just include some Unicode, e.g.:
$ cat /tmp/devpi/test blah blah Miró blah
I noticed this when writing some automation that resets my LC_LANG is reset to "C":
$ sudo salt devpi cmd.run '/bin/bash -c "env"' devpi: LANGUAGE=C LC_ADDRESS=C LC_NAME=C LC_MONETARY=C PWD=/root LC_PAPER=C LANG=en_US.UTF-8 INVOCATION_ID=88480610d5744d4d91c877186fa1a010 LC_IDENTIFICATION=C NOTIFY_SOCKET=/run/systemd/notify SHLVL=0 LC_TELEPHONE=C LC_MESSAGES=C LC_MEASUREMENT=C LC_CTYPE=C LC_TIME=C JOURNAL_STREAM=9:397242 LC_COLLATE=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin LC_NUMERIC=C _=/usr/bin/env
The problem, then:
/usr/bin/python3 is run against the file in this environment, it still reads Unicode strings and all is well. However,
/usr/bin/pypy3 will read
ASCII strings and throws a
/usr/bin/python3, it looks like it might be trying some additional guesses to figure out that it should use UTF-8 and configuring it differently.
If you don't feel this is an issue, I understand, but wanted to raise it as 'a difference' between