[issue9548] locale can be imported at startup but relies on too many library modules

STINNER Victor report at bugs.python.org
Thu Oct 10 09:58:25 CEST 2013


STINNER Victor added the comment:

The io module doesn't need to set temporarly the LC_CTYPE locale (which is a good thing because the change is process-wide!). If we ignore systems where CODESET is not available, the _bootlocale can be simplified to a few lines:

if sys.platform.startswith("win"):
    def getpreferredencoding():
        import _locale
        return _locale._getdefaultlocale()[1]
else:
    def getpreferredencoding():
        result = nl_langinfo(CODESET)
        if not result and sys.platform == 'darwin':
             result = 'UTF-8'
        return result

This code can probably be implemented in C, directly in the _locale module. Would it be acceptable to modify the io module to replace locale.getpreferredencoding(False) with _locale.getpreferredencoding(False)?

Does anyone know if Python does still support systems where CODESET is not available? Which OS does not support CODESET? Would it be acceptable to fallback to locale.py if CODESET is not available?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9548>
_______________________________________


More information about the Python-bugs-list mailing list