Naoki INADA <songofaca...@gmail.com> added the comment: How to use locale.getpreferredencoding() instead of locale.nl_langinfo(locale.CODESET).
--- IOBinding.py.back Sun Apr 12 19:54:52 2009 +++ IOBinding.py Sun Apr 12 20:02:58 2009 @@ -35,40 +35,16 @@ # Encoding for file names filesystemencoding = sys.getfilesystemencoding() -encoding = "ascii" -if sys.platform == 'win32': - # On Windows, we could use "mbcs". However, to give the user - # a portable encoding name, we need to find the code page - try: - encoding = locale.getdefaultlocale()[1] - codecs.lookup(encoding) - except LookupError: - pass -else: - try: - # Different things can fail here: the locale module may not be - # loaded, it may not offer nl_langinfo, or CODESET, or the - # resulting codeset may be unknown to Python. We ignore all - # these problems, falling back to ASCII - encoding = locale.nl_langinfo(locale.CODESET) - if encoding is None or encoding is '': - # situation occurs on Mac OS X - encoding = 'ascii' - codecs.lookup(encoding) - except (NameError, AttributeError, LookupError): - # Try getdefaultlocale well: it parses environment variables, - # which may give a clue. Unfortunately, getdefaultlocale has - # bugs that can cause ValueError. - try: - encoding = locale.getdefaultlocale()[1] - if encoding is None or encoding is '': - # situation occurs on Mac OS X - encoding = 'ascii' - codecs.lookup(encoding) - except (ValueError, LookupError): - pass +encoding = "utf-8" -encoding = encoding.lower() +preferredencoding = None +try: + preferredencoding = locale.getpreferredencoding() + codecs.lookup(preferredencoding) + encoding = preferredencoding.lower() +except LookupError: + pass +del preferredencoding coding_re = re.compile("coding[:=]\s*([-\w_.]+)") ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1542677> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com