Author inada.naoki
Recipients ajaksu2, inada.naoki, kbk, sgala
Date 2009-04-12.11:04:18
SpamBayes Score 3.21642e-07
Marked as misclassified No
Message-id <1239534260.19.0.349075523492.issue1542677@psf.upfronthosting.co.za>
In-reply-to
Content
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_.]+)")
History
Date User Action Args
2009-04-12 11:04:20inada.naokisetrecipients: + inada.naoki, kbk, sgala, ajaksu2
2009-04-12 11:04:20inada.naokisetmessageid: <1239534260.19.0.349075523492.issue1542677@psf.upfronthosting.co.za>
2009-04-12 11:04:19inada.naokilinkissue1542677 messages
2009-04-12 11:04:18inada.naokicreate