Author vstinner
Recipients Arfrever, barry, benjamin.peterson, brett.cannon, christian.heimes, eric.araujo, eric.snow, flox, lemburg, mark.dickinson, ncoghlan, orsenthil, pitrou, rhettinger, vstinner
Date 2013-10-10.07:58:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1381391905.39.0.927277578166.issue9548@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2013-10-10 07:58:25vstinnersetrecipients: + vstinner, lemburg, barry, brett.cannon, rhettinger, mark.dickinson, ncoghlan, orsenthil, pitrou, christian.heimes, benjamin.peterson, eric.araujo, Arfrever, flox, eric.snow
2013-10-10 07:58:25vstinnersetmessageid: <1381391905.39.0.927277578166.issue9548@psf.upfronthosting.co.za>
2013-10-10 07:58:25vstinnerlinkissue9548 messages
2013-10-10 07:58:25vstinnercreate