[issue16162] Py_FileSystemDefaultEncoding should be updated on locale.setlocale()
Michael Vogt added the comment: Thanks for this detailed explaination! I will workaround this outside of python (that is easy ;) - I just thought that it would be a good idea to be able to change the fsencoding (and therefore send the patch), but in the light of e.g. sys.path it seems to be indeed a pretty bad idea. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16162 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16162] Py_FileSystemDefaultEncoding should be updated on locale.setlocale()
New submission from Michael Vogt: The Py_FileSystemDefaultEncoding is very static right now and only set on interpreter statup AFAICT. There appears to be no way to switch that later. I think that Py_FileSystemDefaultEncoding should get updated when locale.setlocale() is run automatically and attach a proof-of-concept patch for this. The reason is that if a python application is started without a environment (dbus activation will do that for example) its impossible to work with utf8 encoded filenames. The only workaround is to setup a environment and then os.execv() which seems not ideal. -- components: Unicode files: alllow-chaning-of-Py_FileSystemDefaultEncoding.diff keywords: patch messages: 172373 nosy: ezio.melotti, mvo priority: normal severity: normal status: open title: Py_FileSystemDefaultEncoding should be updated on locale.setlocale() versions: Python 3.2 Added file: http://bugs.python.org/file27486/alllow-chaning-of-Py_FileSystemDefaultEncoding.diff ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16162 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16162] Py_FileSystemDefaultEncoding should be updated on locale.setlocale()
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +haypo, pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16162 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16162] Py_FileSystemDefaultEncoding should be updated on locale.setlocale()
Martin v. Löwis added the comment: It actually *is* possible to work with UTF-8-encoded file names even in an ASCII locale. It should work automatically, using the PEP 383 mechanism. I'm -0 on allowing changes to the file system encoding. It may lead to mojibake, if some file names were read from the file system before the locale was changed, and then accessed later. I don't understand why you think that it is, in some cases, impossible to pass environment variables. In case of dbus activiation, it is surely possible to pass environment variables somehow. The easiest solution should be to put #!/bin/sh s= LANG=en_US.UTF-8 exec /usr/bin/python $0 $@ ''' into the beginning of the script. -- nosy: +loewis ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16162 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16162] Py_FileSystemDefaultEncoding should be updated on locale.setlocale()
STINNER Victor added the comment: I think that Py_FileSystemDefaultEncoding should get updated when locale.setlocale() is run automatically This is not a good idea. The two following expressions must be True on UNIX: os.fsencode(os.fsdecode(name)) == name os.fsdecode(os.fsencode(name)) == name Said differently: if you change the filesystem encoding, you cannot encode or decode (depending on the type, str or bytes) back the filename. For example, sys.path is a list of filenames filled in an early stage of Python initialization. If you change the filesystem encoding after this list is filled, you may fail to import modules. See also this thread: http://mail.python.org/pipermail/python-dev/2010-October/104509.html -- If you want to change the locale encoding, please do it outside Python (before running Python), and then don't change it again! Example on Ubuntu: $ LC_CTYPE=fr_FR.iso885915@euro python -c 'import sys; print(sys.getfilesystemencoding())' ISO-8859-15 -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16162 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue16162] Py_FileSystemDefaultEncoding should be updated on locale.setlocale()
Changes by R. David Murray rdmur...@bitdance.com: -- resolution: - invalid stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue16162 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com